예제 #1
0
파일: Train.cs 프로젝트: azret/mozart
 static void ScoreMelModel(Set sourceFiles, Matrix Model)
 {
     if (Model == null)
     {
         Console.WriteLine("Model not loaded.");
         return;
     }
     string[] Shuffle = ((IEnumerable <string>)sourceFiles).ToArray();
     foreach (string file in Shuffle)
     {
         Matrix Data = System.Ai.Model.LoadFromFile(file, SIZE, out string fmt, out CBOW.DIMS);
         Debug.Assert(fmt == "MIDI");
         var wo = Model["a"];
         if (wo == null)
         {
             continue;
         }
         foreach (var it in Data)
         {
             double dot = 0.0,
                      score;
             for (int j = 0; j < it.Axis.Length; j++)
             {
                 dot += it.Axis[j].Re * wo.Axis[j].Im;
             }
             score       = Sigmoid.f(dot);
             it.Score.Im = score;
             it.Axis     = null;
         }
         SaveMidi(Data.GetBuffer(), fmt, Path.ChangeExtension(file, ".score"));
     }
 }
예제 #2
0
파일: Mikolov.cs 프로젝트: azret/mozart
 public static Word[] Predict(IEnumerable <Word> Model, float[] Re, int max)
 {
     Word[] best = new Word[max];
     foreach (Word c in Model)
     {
         int b = 0;
         for (int j = 0; j < best.Length; j++)
         {
             if (best[j] == null)
             {
                 b = j;
                 break;
             }
             if (best[j].Re < best[b].Re)
             {
                 b = j;
             }
         }
         float dot = 0,
               score;
         for (int j = 0; j < Re.Length; j++)
         {
             dot += c.Elements[j].Im * Re[j];
         }
         score = (float)Sigmoid.f(dot);
         if (best[b] == null || best[b].Re < score)
         {
             best[b] = new Word(c.Id, c.HashCode)
             {
                 Re = score
             };
         }
     }
     return(best);
 }
예제 #3
0
파일: Fit.cs 프로젝트: azret/mozart
        public static double binaryLogistic(double[] X, double[] W)
        {
            Debug.Assert(X.Length == W.Length);
            int    len = X.Length;
            double Dot = 0.0;

            for (int j = 0; j < len; j++)
            {
                Dot += X[j] * W[j];
            }
            var y = Sigmoid.f(Dot);

            return(y);
        }
예제 #4
0
파일: Mikolov.cs 프로젝트: azret/mozart
        public static double binaryLogistic(double[] wi,
                                            double[] grads, Complex[] wo, double label, double lr)
        {
            if (wo == null)
            {
                return(0);
            }
            Debug.Assert(label >= -1 && label <= 1);
            Debug.Assert(lr >= 0 && lr <= 1);
            int    len = wi.Length;
            double dot = 0.0;

            for (int j = 0; j < len; j++)
            {
                dot += wo[j].Im * wi[j];
            }
            var    y    = Sigmoid.f(dot);
            double diff = lr * (label - y);

            if (double.IsNaN(diff) || double.IsInfinity(diff))
            {
                Console.WriteLine("NaN or Infinity detected...");
                return(diff);
            }
            if (grads != null)
            {
                Debug.Assert(grads.Length == len);
                for (int j = 0; j < len; j++)
                {
                    grads[j] += wo[j].Im * diff;
                }
            }
            for (int j = 0; j < len; j++)
            {
                wo[j].Im += (float)(wi[j] * diff);
            }
            return(y);
        }