package org.mwg.ml.profiling;

import org.junit.Test;
import org.mwg.Callback;
import org.mwg.Graph;
import org.mwg.GraphBuilder;
import org.mwg.ml.algorithm.profiling.GaussianGmmNode;
import org.mwg.core.scheduler.NoopScheduler;

import java.util.Random;

/**
 * Created by assaad on 01/04/16.
 */
public class GaussianMixtureModelTest {
    @Test
    public void mixtureTest() {
        Graph graph = GraphBuilder.builder().withFactory(new GaussianGmmNode.Factory()).withScheduler(new NoopScheduler()).build();
        graph.connect(new Callback<Boolean>() {
            @Override
            public void on(Boolean result) {
                double[] data = new double[3];
                Random rand = new Random();

                GaussianGmmNode node1 = (GaussianGmmNode) graph.newTypedNode(0, 0, "GaussianGmm");
                node1.set(GaussianGmmNode.LEVEL_KEY,1);
                node1.set(GaussianGmmNode.WIDTH_KEY,100);

                for (int i = 0; i < 220; i++) {
                    data[0] = 8 + rand.nextDouble() * 4; //avg =10, [8,12]
                    data[1] = 90 + rand.nextDouble() * 20; //avg=100 [90,110]
                    data[2] = -60 + rand.nextDouble() * 20; //avg=-50 [-60,-40]
                    node1.setTrainingVector(data);

                    node1.learn(new Callback<Boolean>() {
                        @Override
                        public void on(Boolean result) {

                        }
                    });
                }
            }
        });
    }
}

@@ -24,16 +24,41 @@
 iling;%0A%0A
+import org.junit.Assert;%0A
 import o
@@ -148,16 +148,37 @@
 uilder;%0A
+import org.mwg.Type;%0A
 import o
@@ -858,16 +858,17 @@
 nGmm%22);%0A
+%0A
         
@@ -876,32 +876,40 @@
        node1.set
+Property
 (GaussianGmmNode
@@ -919,16 +919,26 @@
 VEL_KEY,
+ Type.INT,
 1);%0A    
@@ -958,16 +958,24 @@
 ode1.set
+Property
 (Gaussia
@@ -997,15 +997,101 @@
 KEY,
+ Type.INT,
 100);%0A%0A
+                double%5B%5D sum=new double%5B3%5D;%0A                int total=220;%0A%0A
     
@@ -1122,19 +1122,21 @@
  0; i %3C 
-220
+total
 ; i++) %7B
@@ -1381,32 +1381,34 @@
                 
+//
 node1.setTrainin
@@ -1454,17 +1454,28 @@
 e1.learn
-(
+Vector(data,
 new Call
@@ -1629,24 +1629,456 @@
          %7D);
+%0A%0A                    sum%5B0%5D+=data%5B0%5D;%0A                    sum%5B1%5D+=data%5B1%5D;%0A                    sum%5B2%5D+=data%5B2%5D;%0A                %7D%0A%0A                sum%5B0%5D= sum%5B0%5D/total;%0A                sum%5B1%5D= sum%5B1%5D/total;%0A                sum%5B2%5D= sum%5B2%5D/total;%0A%0A                double eps=1e-7;%0A%0A                double%5B%5D res= node1.getAvg();%0A                for(int i=0;i%3C3;i++)%7B%0A                    Assert.assertTrue(Math.abs(res%5Bi%5D-sum%5Bi%5D)%3Ceps);
 %0A           

update gmm test