public void SoftsignPrimeTest() { var a = new Matrix(2, 2); a.InRandomize(); var b = a.Duplicate(); a = new Softsign().Backward(a); b.InMap((x) => x / Math.Pow(1 + Math.Abs(x), 2)); Assert.IsTrue(Math.Abs(a.FrobeniusNorm() - b.FrobeniusNorm()) < 0.1, new Softsign().Type().ToString() + " Derivative."); }
public void SoftsignTest() { var a = new Matrix(2, 2); a.InRandomize(); var b = a.Duplicate(); a = new Softsign().Forward(a); b.InMap((x) => x / (1 + Math.Abs(x))); Assert.IsTrue(Math.Abs(a.FrobeniusNorm() - b.FrobeniusNorm()) < 0.1, new Softsign().Type().ToString() + " Activation."); }
public Layer(int nCount, int index, ActivationSettings activationSettings) { NCount = nCount; Index = index; ActivationType = activationSettings.Type(); // Activation Setup switch (activationSettings.Type()) { case EActivationType.Invalid: Activation = null; throw new ArgumentException("Activation Type Invalid."); case EActivationType.Arctan: Activation = new Arctan(); break; case EActivationType.BinaryStep: Activation = new BinaryStep(); break; case EActivationType.BipolarSigmoid: Activation = new BipolarSigmoid(); break; case EActivationType.ELU: Activation = new ELU((ELUSettings)activationSettings); break; case EActivationType.HardSigmoid: Activation = new HardSigmoid(); break; case EActivationType.HardTanh: Activation = new HardTanh(); break; case EActivationType.Identity: Activation = new Identity(); break; case EActivationType.Logit: Activation = new Logit(); break; case EActivationType.LReLU: Activation = new LReLU((LReLUSettings)activationSettings); break; case EActivationType.Mish: Activation = new Mish(); break; case EActivationType.ReLU: Activation = new ReLU(); break; case EActivationType.SeLU: Activation = new SeLU(); break; case EActivationType.Sigmoid: Activation = new Sigmoid(); break; case EActivationType.Softmax: Activation = new Softmax(); break; case EActivationType.Softplus: Activation = new Softplus(); break; case EActivationType.Softsign: Activation = new Softsign(); break; case EActivationType.Tanh: Activation = new Tanh(); break; default: throw new ArgumentException("Activation Type Invalid."); } }
private List <IKernelDescriptor> ReadDescriptors(JObject model) { List <IKernelDescriptor> dscps = model.SelectToken("descriptors").Select(layer => { IKernelDescriptor descriptor = null; String layerName = (String)layer.SelectToken("layer"); switch (layerName) { case "AvgPooling1D": descriptor = new AvgPooling1D( (int)layer.SelectToken("padding"), (int)layer.SelectToken("stride"), (int)layer.SelectToken("kernel_size")); break; case "GlobalAveragePooling1D": descriptor = new GlobalAvgPooling1D(); break; case "AvgPooling2D": descriptor = new AvgPooling2D((int)layer.SelectToken("padding_vl"), (int)layer.SelectToken("padding_hz"), (int)layer.SelectToken("stride_vl"), (int)layer.SelectToken("stride_hz"), (int)layer.SelectToken("kernel_height"), (int)layer.SelectToken("kernel_width")); break; case "GlobalAveragePooling2D": descriptor = new GlobalAvgPooling2D(); break; case "BatchNormalization": descriptor = new BatchNormalization( (int)layer.SelectToken("epsilon")); break; case "Cropping1D": descriptor = new Cropping1D( (int)layer.SelectToken("trimBegin"), (int)layer.SelectToken("trimEnd")); break; case "Cropping2D": descriptor = new Cropping2D( (int)layer.SelectToken("topTrim"), (int)layer.SelectToken("bottomTrim"), (int)layer.SelectToken("leftTrim"), (int)layer.SelectToken("rightTrim")); break; case "MaxPooling1D": descriptor = new MaxPooling1D( (int)layer.SelectToken("padding"), (int)layer.SelectToken("stride"), (int)layer.SelectToken("kernel_size")); break; case "GlobalMaxPooling1D": descriptor = new GlobalMaxPooling1D(); break; case "MaxPooling2D": descriptor = new MaxPooling2D((int)layer.SelectToken("padding_vl"), (int)layer.SelectToken("padding_hz"), (int)layer.SelectToken("stride_vl"), (int)layer.SelectToken("stride_hz"), (int)layer.SelectToken("kernel_height"), (int)layer.SelectToken("kernel_width")); break; case "GlobalMaxPooling2D": descriptor = new GlobalMaxPooling2D(); break; case "Convolution1D": descriptor = new Convolution1D( (int)layer.SelectToken("padding"), (int)layer.SelectToken("stride"), (int)layer.SelectToken("kernel_size"), (int)layer.SelectToken("kernel_num")); break; case "Convolution2D": descriptor = new Convolution2D((int)layer.SelectToken("padding_vl"), (int)layer.SelectToken("padding_hz"), (int)layer.SelectToken("stride_vl"), (int)layer.SelectToken("stride_hz"), (int)layer.SelectToken("kernel_height"), (int)layer.SelectToken("kernel_width"), (int)layer.SelectToken("kernel_num")); break; case "Dense2D": descriptor = new Dense2D((int)layer.SelectToken("units")); break; case "Input2D": descriptor = new Input2D((int)layer.SelectToken("height"), (int)layer.SelectToken("width"), (int)layer.SelectToken("channel"), (int)layer.SelectToken("batch")); break; case "Bias2D": descriptor = new Bias2D(); break; case "Permute": descriptor = new Permute( (int)layer.SelectToken("dim1"), (int)layer.SelectToken("dim2"), (int)layer.SelectToken("dim3")); break; case "Reshape": descriptor = new Reshape2D( (int)layer.SelectToken("height"), (int)layer.SelectToken("width"), (int)layer.SelectToken("channel"), 1); break; case "RepeatVector": descriptor = new RepeatVector( (int)layer.SelectToken("num")); break; case "SimpleRNN": descriptor = new SimpleRNN( (int)layer.SelectToken("units"), (int)layer.SelectToken("input_dim"), ANR((string)layer.SelectToken("activation"))); break; case "LSTM": descriptor = new LSTM( (int)layer.SelectToken("units"), (int)layer.SelectToken("input_dim"), ANR((string)layer.SelectToken("activation")), ANR((string)layer.SelectToken("rec_act"))); break; case "GRU": descriptor = new GRU( (int)layer.SelectToken("units"), (int)layer.SelectToken("input_dim"), ANR((string)layer.SelectToken("activation")), ANR((string)layer.SelectToken("rec_act"))); break; case "ELu": descriptor = new ELu(1); break; case "HardSigmoid": descriptor = new HardSigmoid(); break; case "ReLu": descriptor = new ReLu(); break; case "Sigmoid": descriptor = new Sigmoid(); break; case "Flatten": descriptor = new Flatten(); break; case "Softmax": descriptor = new Softmax(); break; case "SoftPlus": descriptor = new SoftPlus(); break; case "SoftSign": descriptor = new Softsign(); break; case "TanH": descriptor = new TanH(); break; default: throw new Exception("Unknown layer type!"); } return(descriptor); }).ToList(); return(dscps); }