文字“1”中没有(Num [Integer])的实例

时间:2017-11-12 19:51:26

标签: haskell types functional-programming

plus1 :: [Integer] ->  [Integer] -> [Integer] 
plus1 (x:xs) remain  
    | (x==0) && (remain==1) = [1] ++ (plus1 xs (remain-1) )
    | (x==1) && (remain==1) = [0] ++ (plus1 xs remain)
    | (x==0) && (remain==0) = [0] ++ (plus1 xs 0)
    | (x==1) && (remain==0) = [1] ++ (plus1 xs 0)
    |  otherwise = []

•文字“1”

中没有(Num [Integer])的实例

•在'(==)'的第二个参数中,即'1'

在'(&&)'的第二个参数中,即'(保留== 1)'

在表达式中:(x == 0)&& (保持== 1)

1 个答案:

答案 0 :(得分:0)

您的类型签名表明remain应为:: [Integer],但您将其与==1进行比较,其中Integerplus1 :: [Integer] -> Integer -> [Integer]。您的类型签名可能是private object _lock = new object(); public double CalculatePredictedRSquared() { double press = 0, tss = 0, press2 = 0, press1 = 0; Vector<double> output = CreateVector.Dense(Enumerable.Range(0, 400).Select(i => Convert.ToDouble(i)).ToArray()); List<double> input1 = new List<double>(Enumerable.Range(0, 400).Select(i => Convert.ToDouble(i))); List<double> input2 = new List<double>(Enumerable.Range(200, 400).Select(i => Convert.ToDouble(i))); Parallel.For(0, output.Count, i => { ConcurrentBag<MultipleRegressionInfo> listMRInfoBag = new ConcurrentBag<MultipleRegressionInfo>(listMRInfo); ConcurrentBag<double> vectorArrayBag = new ConcurrentBag<double>(output); ConcurrentBag<double[]> matrixList = new ConcurrentBag<double[]>(); lock (_lock) { matrixList.Add(input1.Where((v, k) => k != i).ToArray()); matrixList.Add(input2.Where((v, k) => k != i).ToArray()); } var matrixArray2 = CreateMatrix.DenseOfColumnArrays(matrixList); var actualResult = vectorArrayBag.ElementAt(i); var newVectorArray = CreateVector.Dense(vectorArrayBag.Where((v, j) => j != i).ToArray()); var items = FindBestMRSolution(matrixArray2, newVectorArray); double estimate1 = 0; if (items != null) { lock (_lock) { var y = 0d; var independentCount = matrixArray2.RowCount; var dependentCount = newVectorArray.Count; if (independentCount == dependentCount) { var populationCount = independentCount; y = newVectorArray.Average(); for (int l = 0; l < matrixArray2.ColumnCount; l++) { var avg = matrixArray2.Column(l).Average(); y -= avg * items[l]; } } for (int m = 0; m < 2; m++) { var coefficient = items[m]; if (m == 0) { estimate1 += input1.ElementAt(i) * coefficient; } else { estimate1 += input2.ElementAt(i) * coefficient; } } estimate1 += y; } } else { lock (_lock) { estimate1 = 0; } } lock (_lock) { press1 += Math.Pow(actualResult - estimate1, 2); } }); for (int i = 0; i < output.Count; i++) { List<double[]> matrixList = new List<double[]>(); matrixList.Add(input1.Where((v, k) => k != i).ToArray()); matrixList.Add(input2.Where((v, k) => k != i).ToArray()); var matrixArray = CreateMatrix.DenseOfColumnArrays(matrixList); var actualResult = output.ElementAt(i); var newVectorArray = CreateVector.Dense(output.Where((v, j) => j != i).ToArray()); var items = FindBestMRSolution(matrixArray, newVectorArray); double estimate = 0; if (items != null) { var y = CalculateYIntercept(matrixArray, newVectorArray, items); for (int m = 0; m < 2; m++) { var coefficient = items[m]; if (m == 0) { estimate += input1.ElementAt(i) * coefficient; } else { estimate += input2.ElementAt(i) * coefficient; } } } else { estimate = 0; } press2 += Math.Pow(actualResult - estimate, 2); } tss = CalculateTotalSumOfSquares(vectorArray.ToList()); var test1 = 1 - (press1 / tss); var test2 = 1 - (press2 / tss); } public Vector<double> CalculateWithQR(Matrix<double> x, Vector<double> y) { Vector<double> result = null; result = MultipleRegression.QR(x, y); for (int i = 0; i < result.Count; i++) { var value = result.ElementAt(i); if (Double.IsNaN(value) || Double.IsInfinity(value)) { return null; } } return result; } public Vector<double> CalculateWithNormal(Matrix<double> x, Vector<double> y) { Vector<double> result = null; result = MultipleRegression.NormalEquations(x, y); for (int i = 0; i < result.Count; i++) { var value = result.ElementAt(i); if (Double.IsNaN(value) || Double.IsInfinity(value)) { return null; } } return result; } public Vector<double> CalculateWithSVD(Matrix<double> x, Vector<double> y) { Vector<double> result = null; result = MultipleRegression.Svd(x, y); for (int i = 0; i < result.Count; i++) { var value = result.ElementAt(i); if (Double.IsNaN(value) || Double.IsInfinity(value)) { return null; } } return result; } public Vector<double> FindBestMRSolution(Matrix<double> x, Vector<double> y) { Vector<double> result = null; result = CalculateWithNormal(x, y); if (result != null) { return result; } else { result = CalculateWithSVD(x, y); if (result != null) { return result; } else { result = CalculateWithQR(x, y); if (result != null) { return result; } } } return result; } public double CalculateTotalSumOfSquares(List<double> dependentVariables) { double tts = 0; for (int i = 0; i < dependentVariables.Count; i++) { tts += Math.Pow(dependentVariables.ElementAt(i) - dependentVariables.Average(), 2); } return tts; }