public void Score(List <NetworkState> states, TrainingSample sample)
        {
            var availableOnsets = sample.Frames.Where(frame => frame.IsOnset).ToList();
            int totalSelection  = availableOnsets.Count(); // tp + fn

            for (int i = 1; i < states.Count; i++)
            {
                NetworkState state = states[i];
                double       time  = sample.Frames[i - 1].Frame.Start;

                Debug.Assert(state.Output.Length == 1);
                if (state.Output[0] < 0.25)
                {
                    continue;                        // < state.Output[1]) continue;
                }
                TrainingFrame matchedOnset = availableOnsets.FirstOrDefault(onset => Math.Abs(onset.Frame.Start - time) < MatchingTolerance);
                if (matchedOnset != null)
                {
                    availableOnsets.Remove(matchedOnset);
                    truePositives++;
                }
                else
                {
                    falsePositives++;
                }
            }
            falseNegatives += availableOnsets.Count;
        }
Exemple #2
0
        public void Train(TrainingSample sample, NetworkScorer scorer)
        {
            List <NetworkState> states = FeedForward(sample, scorer);

            trainingState.Prepare(momentum: Momentum);

            // Backpropogate through time.
            for (int i = states.Count - 1; i >= 1; i--)
            {
                // Get the corresponding frame.
                TrainingFrame frame   = sample.Frames[i - 1];
                NetworkState  current = states[i];
                NetworkState  last    = states[i - 1];

                //bool annotatedOnsetNearby = IsAnnotatedOnsetNearby(sample, states, i);

                double onCorrect = frame.IsOnset ? DetectionValue : NoDetectionValue;
                //double offCorrect = frame.IsOnset ? 0.0 : 1.0;

                trainingState.Errors[0] = (current.Output[0] - onCorrect);
                // trainingState.Errors[1] = (current.Output[1] - offCorrect);

                trainingState.BackPropogate(last: last, now: current);
            }

            // Apply the required weight changes.
            trainingState.ApplyWeightChanges(LearningCoefficient);
        }
        public static Bitmap Draw(TrainingSample sample)
        {
            var frames = sample.Frames;
            int height = frames[0].Frame.Values.Length;

            Debug.Assert(height % 6 == 0);

            int    bands  = height / 6;
            Bitmap result = new Bitmap(frames.Length, bands * 6 + 5);

            for (int x = 0; x < frames.Length; x++)
            {
                TrainingFrame frame = frames[x];
                DrawRow(result, x, frame);
            }
            return(result);
        }
        private static void DrawRow(Bitmap bitmap, int x, TrainingFrame frame)
        {
            double[] values = frame.Frame.Values;
            int      bands  = (bitmap.Height - 5) / 6;
            int      y      = 0;
            int      index  = 0;

            for (int part = 0; part < 6; part++)
            {
                for (int i = 0; i < bands; i++)
                {
                    bitmap.SetPixel(x, y++, GetColor(values[index++], frame.IsOnset));
                }

                if (part < 5)
                {
                    bitmap.SetPixel(x, y++, Color.Black);
                }
            }
        }