public SmoRandomSolver(Problem <TProblemElement> problem, IKernel <TProblemElement> kernel, float C) : base(problem, kernel, C) { //remeber that we have variable kernel in base class Q = new CachedKernel <TProblemElement>(problem, kernel); // (CachedKernel)kernel; QD = Q.GetQD(); // Shrinking = false; //todo: change it, add array to base class with different penalty for labels Cp = C; Cn = C; problemSize = problem.ElementsCount; }
public ParallelSmoFanSolver(Problem <TProblemElement> problem, IKernel <TProblemElement> kernel, float C) : base(problem, kernel, C) { //todo: add checking if kernel is initialized //remeber that we have variable kernel in base class Q = new CachedKernel <TProblemElement>(problem, kernel); //get diagonal cache, kernel should compute that QD = Q.GetQD(); //Shrinking = false; //todo: change it, add array to base class with different penalty for labels Cp = C; Cn = C; problemSize = problem.ElementsCount; int rangeSize = (int)Math.Ceiling((problemSize + 0.0) / Environment.ProcessorCount); // partition= Partitioner.Create( 0, problemSize,rangeSize); }
public ParallelSmoFanSolver2(Problem <TProblemElement> problem, IKernel <TProblemElement> kernel, float C) : base(problem, kernel, C) { //todo: add checking if kernel is initialized //remeber that we have variable kernel in base class Q = new CachedKernel <TProblemElement>(problem, kernel); //get diagonal cache, kernel should compute that QD = Q.GetQD(); //Shrinking = false; //todo: change it, add array to base class with different penalty for labels Cp = C; Cn = C; problemSize = problem.ElementsCount; numberOfThreads = Environment.ProcessorCount; rangeSize = (int)Math.Ceiling((problemSize + 0.0) / numberOfThreads); partition = Partitioner.Create(0, problemSize, rangeSize); resetEvents = new ManualResetEvent[numberOfThreads]; //max data structures maxPairsWaitCallbacks = new WaitCallback[numberOfThreads]; //data for finding maxPair in svm solver maxPairThreadsData = new MaxFindingThreadData[numberOfThreads]; maxPairs = new Pair <int, float> [numberOfThreads]; //min data structures minPairsWaitCallbacks = new WaitCallback[numberOfThreads]; //data for finding minPair in svm solver minPairThreadsData = new MinFindingThreadData[numberOfThreads]; minPairs = new Pair <int, float> [numberOfThreads]; //int startRange = 0; //int endRange = startRange + rangeSize; Tuple <int, int>[] ranges = ListHelper.CreateRanges(problemSize, numberOfThreads); for (int i = 0; i < numberOfThreads; i++) { resetEvents[i] = new ManualResetEvent(false); maxPairs[i] = new Pair <int, float>(-1, float.NegativeInfinity); maxPairThreadsData[i] = new MaxFindingThreadData() { ResetEvent = resetEvents[i], Pair = maxPairs[i], //Range = new Tuple<int, int>(startRange, endRange) Range = ranges[i] }; maxPairsWaitCallbacks[i] = new WaitCallback(this.FindMaxPairInThread); minPairs[i] = new Pair <int, float>(-1, float.PositiveInfinity); minPairThreadsData[i] = new MinFindingThreadData() { ResetEvent = resetEvents[i], Pair = minPairs[i], //Range = new Tuple<int, int>(startRange, endRange) Range = ranges[i] }; minPairsWaitCallbacks[i] = new WaitCallback(this.FindMinPairInThread); //change the range //startRange = endRange; //int rangeSum = endRange + rangeSize; //endRange = rangeSum < problemSize ? rangeSum : problemSize; } }