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; } }
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"); }
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 !"); }
void CreateModel() { this.model = LinearClassification.linear_model_create(2); Debug.Log("Created model"); }
void CreateModel(int nbDimension) { this.model = LinearClassification.linear_model_create(nbDimension); Debug.Log("Created model"); }