Пример #1
0
        public void CalculateMSE(SupervisedBatch batch, DataArray mseValues, int valueIndex)
        {
            Args.Requires(() => batch, () => batch != null);
            Args.Requires(() => batch, () => batch.Count > 0);
            Args.Requires(() => mseValues, () => mseValues != null);
            Args.Requires(() => valueIndex, () => valueIndex >= 0 && valueIndex < mseValues.Size);

            DoCalculateMSE(batch, mseValues, valueIndex);
        }
Пример #2
0
        public SupervisedSampleEntry(DataArray input, DataArray desiredOutput, DataArray actualOutput)
        {
            Args.Requires(() => input, () => input != null);
            Args.Requires(() => desiredOutput, () => desiredOutput != null);
            Args.Requires(() => actualOutput, () => actualOutput != null);
            Args.Requires(() => actualOutput, () => desiredOutput.Size == actualOutput.Size);

            Input = input;
            DesiredOutput = desiredOutput;
            ActualOutput = actualOutput;
        }
Пример #3
0
        protected override void DoCalculateMSE(SupervisedBatch batch, DataArray mseValues, int valueIndex)
        {
            var mseA = mseValues.ToManaged();
            fixed (float* pMseA = mseA.InternalArray)
            {
                var msePtr = mseA.ToPtr(pMseA);

                msePtr[valueIndex] = 0.0f;
                float count = 0.0f;
                foreach (var sample in batch)
                {
                    foreach (var entry in sample)
                    {
                        if (entry.HasOutput)
                        {
                            var actualOutputs = entry.ActualOutput.ToManaged();
                            var desiredOutputs = entry.DesiredOutput.ToManaged();
                            fixed (float* pAO = actualOutputs.InternalArray, pDO = desiredOutputs.InternalArray)
                            {
                                var aoPtr = actualOutputs.ToPtr(pAO);
                                var doPtr = desiredOutputs.ToPtr(pDO);
                                float cMse = 0.0f;

                                for (int x = 0; x < actualOutputs.Size; x++)
                                {
                                    float error = (doPtr[x] - aoPtr[x]) * 0.5f;
                                    cMse += error * error;
                                }
                                msePtr[valueIndex] += cMse / (float)actualOutputs.Size;

                                count++;
                            }
                        }
                    }
                }

                if (count != 0.0f) msePtr[valueIndex] /= count;
            }
        }
Пример #4
0
 protected abstract void DoCalculateMSE(SupervisedBatch batch, DataArray mseValues, int valueIndex);
Пример #5
0
 public void CalculateMSE(SupervisedSample sample, DataArray mseValues, int valueIndex)
 {
     CalculateMSE(new SupervisedBatch(sample), mseValues, valueIndex);
 }
Пример #6
0
        public void CalculateMSE(SupervisedSampleEntry sampleEntry, DataArray mseValues, int valueIndex)
        {
            Args.Requires(() => sampleEntry, () => sampleEntry != null && sampleEntry.HasOutput);

            CalculateMSE(new SupervisedSample(sampleEntry), mseValues, valueIndex);
        }
Пример #7
0
 public void CalculateMSE(DataArray input, DataArray desiredOutput, DataArray actualOutput, DataArray mseValues, int valueIndex)
 {
     CalculateMSE(new SupervisedSampleEntry(input, desiredOutput, actualOutput), mseValues, valueIndex);
 }
Пример #8
0
        public SupervisedSampleEntry(DataArray input)
        {
            Args.Requires(() => input, () => input != null);

            Input = input;
        }