public ThreadDistributorTriangularMatrix(int nThreads, int n, Action<int, int> calculation) { int nTasks = n*(n - 1)/2; nThreads = Math.Min(nThreads, nTasks); td = new ThreadDistributor(nThreads, nTasks, i =>{ int j; int k; GetIndices(i, out j, out k); calculation(j, k); }); }
public ThreadDistributorTriangularMatrix(int nThreads, int n, Action <int, int> calculation) { int nTasks = n * (n - 1) / 2; nThreads = Math.Min(nThreads, nTasks); td = new ThreadDistributor(nThreads, nTasks, i => { int j; int k; GetIndices(i, out j, out k); calculation(j, k); }); }
public override ClassificationModel Train(BaseVector[] x, int[][] y, int ngroups, Parameters param, int nthreads, Action<double> reportProgress) { string err = CheckInput(x, y, ngroups); if (err != null){ throw new Exception(err); } ParameterWithSubParams<int> kernelParam = param.GetParamWithSubParams<int>("Kernel"); SvmParameter sp = new SvmParameter{ kernelFunction = KernelFunctions.GetKernelFunction(kernelParam.Value, kernelParam.GetSubParameters()), svmType = SvmType.CSvc, c = param.GetParam<double>("C").Value }; bool[] invert; SvmProblem[] problems = CreateProblems(x, y, ngroups, out invert); SvmModel[] models = new SvmModel[problems.Length]; ThreadDistributor td = new ThreadDistributor(nthreads, models.Length, i => { models[i] = SvmMain.SvmTrain(problems[i], sp); }, fractionDone => { reportProgress?.Invoke(fractionDone); }); td.Start(); return new SvmClassificationModel(models, invert); }
public ClassificationModel TrainGroupWise(BaseVector[] x, int[][] y, int ngroups, IGroupDataProvider data, int nthreads) { ClassificationModel[] c = new ClassificationModel[ngroups]; ThreadDistributor td = new ThreadDistributor(nthreads, ngroups, i => { c[i] = TrainGroupWise(i, y, x, data); }); td.Start(); return new GroupWiseClassifier(c); }