Ejemplo n.º 1
0
        /// <summary>
        /// Checks whether the network configuration is suitable for the specified type of the network output.
        /// </summary>
        /// <param name="outputType">The type of the network output.</param>
        /// <param name="netCfg">The network configuration.</param>
        public static void CheckNetCfg(TNRNet.OutputType outputType, INonRecurrentNetworkSettings netCfg)
        {
            switch (outputType)
            {
            case TNRNet.OutputType.Probabilistic:
            {
                if (netCfg.GetType() != typeof(FeedForwardNetworkSettings))
                {
                    throw new ArgumentException($"Incorrect network configuration. It must be the Feed forward network configuration.", "netCfg");
                }
                if (((FeedForwardNetworkSettings)netCfg).OutputActivationCfg.GetType() != typeof(AFAnalogSoftMaxSettings))
                {
                    throw new ArgumentException($"Feed forward network must have the SoftMax output activation.", "netCfg");
                }
                if (((FeedForwardNetworkSettings)netCfg).TrainerCfg.GetType() != typeof(RPropTrainerSettings))
                {
                    throw new ArgumentException($"Feed forward network must have associated the RProp trainer.", "netCfg");
                }
            }
            break;

            case TNRNet.OutputType.Real:
            {
                if (netCfg.GetType() != typeof(FeedForwardNetworkSettings))
                {
                    throw new ArgumentException($"Incorrect network configuration. It must be the Feed forward network configuration.", "netCfg");
                }
            }
            break;

            default:
                break;
            }
            return;
        }
Ejemplo n.º 2
0
 //Constructor
 /// <summary>
 /// Creates an uninitialized instance.
 /// </summary>
 /// <param name="chainName">The name of the cluster chain.</param>
 /// <param name="outputType">The type of output.</param>
 public TNRNetClusterChain(string chainName, TNRNet.OutputType outputType)
 {
     ChainName          = chainName;
     Output             = outputType;
     _clusterCollection = new List <TNRNetCluster>();
     return;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates an uninitialized instance.
 /// </summary>
 /// <param name="clusterName">The name of the cluster.</param>
 /// <param name="outputType">The type of output.</param>
 public ClusterErrStatistics(string clusterName, TNRNet.OutputType outputType)
 {
     ClusterName          = clusterName;
     NatPrecissionErrStat = new BasicStat();
     NrmPrecissionErrStat = new BasicStat();
     if (TNRNet.IsBinErrorStatsOutputType(outputType))
     {
         BinaryErrStat = new BinErrStat(TNRNet.GetOutputDataRange(outputType).Mid);
     }
     else
     {
         BinaryErrStat = null;
     }
     return;
 }
Ejemplo n.º 4
0
 //Constructor
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="networkName">The name of the network to be built.</param>
 /// <param name="networkCfg">The configuration of the network to be built.</param>
 /// <param name="networkOutput">The type of output of the network to be built.</param>
 /// <param name="trainingBundle">The bundle of input and ideal vectors to be used for the network training.</param>
 /// <param name="testingBundle">The bundle of input and ideal vectors to be used for the network testing.</param>
 /// <param name="rand">The random generator to be used (optional).</param>
 /// <param name="controller">The build process controller (optional).</param>
 public TNRNetBuilder(string networkName,
                      INonRecurrentNetworkSettings networkCfg,
                      TNRNet.OutputType networkOutput,
                      VectorBundle trainingBundle,
                      VectorBundle testingBundle,
                      Random rand = null,
                      BuildControllerDelegate controller = null
                      )
 {
     _networkName = networkName;
     NonRecurrentNetUtils.CheckNetCfg(networkOutput, networkCfg);
     _networkCfg    = networkCfg;
     _networkOutput = networkOutput;
     NonRecurrentNetUtils.CheckData(_networkOutput, trainingBundle);
     _trainingBundle = trainingBundle;
     NonRecurrentNetUtils.CheckData(_networkOutput, testingBundle);
     _testingBundle = testingBundle;
     _rand          = rand ?? new Random(0);
     _controller    = controller ?? DefaultNetworkBuildController;
     return;
 }
Ejemplo n.º 5
0
 //Constructor
 /// <summary>
 /// Creates an uninitialized instance.
 /// </summary>
 /// <param name="clusterName">The name of the cluster.</param>
 /// <param name="outputType">The type of output.</param>
 /// <param name="trainingGroupWeight">The macro-weight of the group of metrics related to training.</param>
 /// <param name="testingGroupWeight">The macro-weight of the group of metrics related to testing.</param>
 /// <param name="samplesWeight">The weight of the number of samples metric.</param>
 /// <param name="precisionWeight">The weight of the numerical precision metric.</param>
 /// <param name="misrecognizedFalseWeight">The weight of the "misrecognized falses" metric.</param>
 /// <param name="unrecognizedTrueWeight">The weight of the "unrecognized trues" metric.</param>
 public TNRNetCluster(string clusterName,
                      TNRNet.OutputType outputType,
                      double trainingGroupWeight      = 1d,
                      double testingGroupWeight       = 1d,
                      double samplesWeight            = 1d,
                      double precisionWeight          = 1d,
                      double misrecognizedFalseWeight = 1d,
                      double unrecognizedTrueWeight   = 0d
                      )
 {
     ClusterName                 = clusterName;
     Output                      = outputType;
     _trainingGroupWeight        = trainingGroupWeight;
     _testingGroupWeight         = testingGroupWeight;
     _samplesWeight              = samplesWeight;
     _precisionWeight            = precisionWeight;
     _misrecognizedFalseWeight   = misrecognizedFalseWeight;
     _unrecognizedTrueWeight     = unrecognizedTrueWeight;
     ErrorStats                  = new ClusterErrStatistics(ClusterName, outputType);
     _memberNetCollection        = new List <TNRNet>();
     _memberNetScopeIDCollection = new List <int>();
     _memberNetWeights           = null;
     return;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks whether the data is in accordance with the specified type of the network output.
        /// </summary>
        /// <param name="outputType">The type of the network output.</param>
        /// <param name="data">The data to be checked.</param>
        public static void CheckData(TNRNet.OutputType outputType, VectorBundle data)
        {
            //General checks
            if (data.InputVectorCollection.Count != data.OutputVectorCollection.Count)
            {
                throw new ArgumentException($"Incorrect data. Different number of input and output vectors.", "data");
            }
            if (data.OutputVectorCollection.Count < 2)
            {
                throw new ArgumentException($"Too few samples.", "data");
            }
            int outputVectorLength = data.OutputVectorCollection[0].Length;

            //Output vector length checks
            if (outputType == TNRNet.OutputType.Probabilistic)
            {
                if (outputVectorLength <= 1)
                {
                    throw new ArgumentException($"Number of output vector values must be GT 1.", "data");
                }
            }
            else if (outputType == TNRNet.OutputType.SingleBool)
            {
                if (outputVectorLength != 1)
                {
                    throw new ArgumentException($"Number of output vector values must be ET 1.", "data");
                }
            }
            //Data scan
            foreach (double[] outputVector in data.OutputVectorCollection)
            {
                if (outputVectorLength != outputVector.Length)
                {
                    throw new ArgumentException($"Inconsistent length of output vectors.", "data");
                }
                switch (outputType)
                {
                case TNRNet.OutputType.Probabilistic:
                {
                    int bin1Counter = 0;
                    int bin0Counter = 0;
                    for (int i = 0; i < outputVector.Length; i++)
                    {
                        if (outputVector[i] == 0d)
                        {
                            ++bin0Counter;
                        }
                        else if (outputVector[i] == 1d)
                        {
                            ++bin1Counter;
                        }
                        else
                        {
                            throw new ArgumentException($"Output data vectors contain different values than 0 or 1.", "data");
                        }
                    }
                    if (bin1Counter != 1)
                    {
                        throw new ArgumentException($"Output data vector contains more than one 1.", "data");
                    }
                }
                break;

                case TNRNet.OutputType.SingleBool:
                {
                }
                break;

                default:
                    break;
                }
            }
            return;
        }