locked
Save model of BPM RRS feed

  • Question

  • Hello,

    How can I save the model of the Bayes Point Machine. I need to save data between sessions because my application is executed several times.

    I can not save the entire class BPM (binary or XML serialization), this does not work.

    I tied to instantiate a new BPM class with:

    BPM bpmIncremental2 = new BPM(nClass, totalFeatures, noisePrec);

    and then I set the old values (from previous session) of BPMVarsForTrain.wInit, but this is not enough. Do I need the BPMVarsForTrain.w values also?

    Sunday, March 3, 2013 3:06 AM

Answers

  • The Infer.NET model itself is developer's code and hence is tricky to serialize. What you want to do is to serialize the parameters of the model. When you deserialize, you should have the model code at hand and set the deserialized parameters as observed values. As to the BPM, on deserialization you should set the observed values of the weights and the noise.

    Monday, March 4, 2013 10:16 AM

All replies

  • The Infer.NET model itself is developer's code and hence is tricky to serialize. What you want to do is to serialize the parameters of the model. When you deserialize, you should have the model code at hand and set the deserialized parameters as observed values. As to the BPM, on deserialization you should set the observed values of the weights and the noise.

    Monday, March 4, 2013 10:16 AM
  • Yes, it worked. I used this class to save the model state:

    [Serializable]
    struct SerializationObject
    {
        public int nClass;
        public int nFeatures;
        public double noisePrec;
        public VectorGaussian[] wInitTrainModel;
    }

    Serialization is:

    SerializationObject s;
    s.nClass = nClass;
    s.nFeatures = totalFeatures;
    s.noisePrec = noisePrec;
    s.wInitTrainModel = bpmIncremental.TrainedModel.wInit;

    SerializeObject(s); //binary serialization

    Deserialization code is:

    SerializationObject d = DeSerializeObject(model);
    noisePrec = d.noisePrec;
    totalFeatures = d.nFeatures;
    nClass = d.nClass;

    bpmIncremental = new BPM(nClass, totalFeatures, noisePrec);
    bpmIncremental.TrainedModel.wInit = d.wInitTrainModel;

    You can actually add Save/Load model methods in the future.

    I have compiled BPM to an assembly that can be used as if it was unmanaged C++ DLL. This way I was able to incorporated BPM in a C++ application for BCI (Brain Computer Interface). Now some testing is needed :)

    -Anton

    Wednesday, March 6, 2013 9:14 PM