Ejemplo n.º 1
0
    public void PredictCross()
    {
        if (this.model == null)
        {
            Debug.Log("Create model before");
            return;
        }

        // Call lib to predict test spheres
        foreach (var testSphere in testSpheres)
        {
            var position            = testSphere.position;
            var transformedPosition = TransformCross(position);

            double[] inputs    = { transformedPosition.x, transformedPosition.z };
            var      predicted = LinearClassification.linear_model_predict_classification(this.model.Value, 2, inputs);

            position = new Vector3(
                position.x,
                predicted * (float)0.5,
                position.z
                );

            testSphere.position = position;
        }
    }
Ejemplo n.º 2
0
    public void PredictXor()
    {
        if (this.model == null)
        {
            Debug.Log("Create model before");
            return;
        }

        // Call lib to predict test spheres
        foreach (var testSphere in testSpheres)
        {
            var      position  = testSphere.position;
            double[] inputs    = { Math.Pow(position.x + position.z, 2) };
            var      predicted = LinearClassification.linear_model_predict_classification(this.model.Value, 1, inputs);

            position = new Vector3(
                position.x,
                predicted * (float)0.5,
                position.z
                );

            testSphere.position = position;
        }

        Debug.Log("Predicted");
    }
Ejemplo n.º 3
0
    public void Train()
    {
        CreateModel(2);

        // Call lib to train on the array
        var trainingSphereNumber    = trainingSpheres.Length;
        var trainingInputs          = new double[trainingSphereNumber * 2];
        var trainingExpectedOutputs = new double[trainingSphereNumber];

        for (var i = 0; i < trainingSphereNumber; i++)
        {
            trainingInputs[i * 2]      = trainingSpheres[i].position.x;
            trainingInputs[i * 2 + 1]  = trainingSpheres[i].position.z;
            trainingExpectedOutputs[i] = trainingSpheres[i].position.y;
        }
        LinearClassification.linear_model_train_classification(this.model.Value, 2, epoch, 0.001, trainingInputs, trainingSphereNumber, trainingExpectedOutputs);
        Debug.Log("Model trained !");
    }
Ejemplo n.º 4
0
 void CreateModel()
 {
     this.model = LinearClassification.linear_model_create(2);
     Debug.Log("Created model");
 }
Ejemplo n.º 5
0
 void CreateModel(int nbDimension)
 {
     this.model = LinearClassification.linear_model_create(nbDimension);
     Debug.Log("Created model");
 }