Returns the appropriate callback function for the selected cost function

@return \Closure

@throws \Exception
420802
protected function getCostFunction()
    {
        $penalty = 0;
        if ($this->penalty == 'L2') {
            $penalty = $this->lambda;
        }

        switch ($this->costFunction) {
            case 'log':
                /*
                 * Negative of Log-likelihood cost function to be minimized:
                 *		J(x) = ∑( - y . log(h(x)) - (1 - y) . log(1 - h(x)))
                 *
                 * If regularization term is given, then it will be added to the cost:
                 *		for L2 : J(x) = J(x) +  λ/m . w
                 *
                 * The gradient of the cost function to be used with gradient descent:
                 *		∇J(x) = -(y - h(x)) = (h(x) - y)
                 */
                $callback = function ($weights, $sample, $y) use ($penalty) {
                    $this->weights = $weights;
                    $hX = $this->output($sample);

                    // In cases where $hX = 1 or $hX = 0, the log-likelihood
                    // value will give a NaN, so we fix these values
                    if ($hX == 1) {
                        $hX = 1 - 1e-10;
                    }
                    if ($hX == 0) {
                        $hX = 1e-10;
                    }
                    $error = -$y * log($hX) - (1 - $y) * log(1 - $hX);
                    $gradient = $hX - $y;

                    return [$error, $gradient, $penalty];
                };

                return $callback;

            case 'sse':
                /*
                 * Sum of squared errors or least squared errors cost function:
                 *		J(x) = ∑ (y - h(x))^2
                 *
                 * If regularization term is given, then it will be added to the cost:
                 *		for L2 : J(x) = J(x) +  λ/m . w
                 *
                 * The gradient of the cost function:
                 *		∇J(x) = -(h(x) - y) . h(x) . (1 - h(x))
                 */
                $callback = function ($weights, $sample, $y) use ($penalty) {
                    $this->weights = $weights;
                    $hX = $this->output($sample);

                    $error = ($y - $hX) ** 2;
                    $gradient = -($y - $hX) * $hX * (1 - $hX);

                    return [$error, $gradient, $penalty];
                };

                return $callback;

            default:
                throw new \Exception(sprintf('Logistic regression has invalid cost function: %s.', $this->costFunction));
        }
    }
96659
private static function getDeclareErrorAdvice(): Closure
    {
        static $adviceMethod;
        if (!$adviceMethod) {
            $adviceMethod = function ($object, $reflectorName, $message, $level = E_USER_NOTICE) {
                $class   = is_string($object) ? $object : get_class($object);
                $message = vsprintf('[AOP Declare Error]: %s has an error: "%s"', [
                    $class . '->' . $reflectorName,
                    $message
                ]);
                trigger_error($message, $level);
            };
        }

        return $adviceMethod;
    }
598998
protected function parseCall()
    {

        if ($this->call instanceof Closure) {
            $this->callClass = Closure::class;
            $this->callMethod = '';
            $this->isStaticMethod = false;
            $this->isFunction = false;
            $this->isClosure = true;
            return;
        }

        list($class, $method) = $this->toClassAndMethod($this->call);

        if ($class === '') {
            $this->callClass = '';
            $this->callMethod = $method;
            $this->isStaticMethod = false;
            $this->isFunction = true;
            $this->isClosure = false;
            return;
        }

        $this->callClass = $class;
        $this->callMethod = $method;
        $this->isFunction = false;
        $this->isClosure = false;

        $reflection = new ReflectionMethod($class, $method);
        $this->isStaticMethod = $reflection->isStatic();

        if (!$reflection->isPublic()) {
            throw new LogicException("Method '$method' of $class is not public and therefore not callable.");
        }

        return;

    }
750529
protected function getSlice()
    {
        return function ($stack, $pipe) {
            return function ($passable) use ($stack, $pipe) {
                return call_user_func($pipe, $passable, $stack);
            };
        };
    }
762108
protected function getCreateAnalyzerClosure()
    {
        return function ($app) {
            /** @var AnalysisStrategyInterface $strategy */
            $strategy = $app[AnalysisStrategyInterface::class];
            $analyzer = Analyzer::instance($strategy);

            $logger = $this->getLoggerIfEnabled($app);
            $logger === null ?: $analyzer->setLogger($logger);

            return $analyzer;
        };
    }
262303
public function getIterator()
    {
        if (is_null($i = $this->model ?: $this->dq ?: $this->iter)) {
            throw $this->exception('Please specify data source with setSource or setModel');
        }
        if ($i instanceof Closure) {
            $i = call_user_func($i);
        }

        return $i;
    }
523134
protected function getMacroFunction($macro_func)
    {
        if (is_array($macro_func) && is_callable($macro_func)) {
            return new \ReflectionMethod($macro_func[0], $macro_func[1]);
        }

        if (is_object($macro_func) && is_callable($macro_func) && !$macro_func instanceof Closure) {
            return new \ReflectionMethod($macro_func, '__invoke');
        }

        return new \ReflectionFunction($macro_func);
    }
390429
protected function totalAmountResourceCallable()
    {
        return function () {
            $idKey = $this->getDataModel()->getKeyName();

            return $this->getDataModel()->query()->count([$idKey]);
        };
    }
833512
public function proceed()
    {
        if (isset($this->advices[$this->current])) {
            $currentInterceptor = $this->advices[$this->current++];

            return $currentInterceptor->invoke($this);
        }

        // Rebind the closure if scope (class name) was changed since last time
        if ($this->previousScope !== $this->instance) {
            if ($this->closureToCall === null) {
                $this->closureToCall = static::getStaticInvoker($this->className, $this->reflectionMethod->name);
            }
            $this->closureToCall = $this->closureToCall->bindTo(null, $this->instance);
            $this->previousScope = $this->instance;
        }

        return ($this->closureToCall)($this->arguments);

    }
1236483
private function getCallback($callback)
    {
        if (is_callable($callback)) {
            if (is_array($callback)) {
                $callback = function (Edge $edge) use ($callback) {
                    return call_user_func($callback, $edge);
                };
            }
            return $callback;
        }

        static $methods = array(
            self::ORDER_WEIGHT => 'getWeight',
            self::ORDER_CAPACITY => 'getCapacity',
            self::ORDER_CAPACITY_REMAINING => 'getCapacityRemaining',
            self::ORDER_FLOW => 'getFlow'
        );

        if (!is_int($callback) || !isset($methods[$callback])) {
            throw new InvalidArgumentException('Invalid callback given');
        }

        $method = $methods[$callback];

        return function (Edge $edge) use ($method) {
            return $edge->$method();
        };
    }
462273
public function getFilterCallback()
    {
        if ($this->filterCallback !== null) {
            $callback = $this->filterCallback;
        } else {
            $field = $this->field;

            $callback = function ($value) use ($field) {
                return [$field => $value];
            };
        }

        return $callback;
    }
762969
public function getHandler()
    {
        if (is_callable($this->handler)) {
            return $this->handler;
        }

        $options = $this->options;

        return function ($value) use ($options) {
            if (in_array($value, $options)) {
                return true;
            }

            return false;
        };
    }
144104
function getCurrency(): \Closure {
    return function($value, \Mustache_LambdaHelper $helper) {
      $args = $this->parseArguments($helper->render($value), 'value', [
        'currency' => null,
        'options' => [],
        'textOptions' => []
      ]);

      return HtmlHelper::encode(\Yii::$app->formatter->asCurrency(
        $args['value'],
        $args['currency'],
        $args['options'],
        $args['textOptions']
      ));
    };
  }
763152
public function log() : \Closure
    {
        $logger    = $this->logger;
        $formatter = $this->formatter;

        return function (callable $handler) use ($logger, $formatter) {

            return function ($request, array $options) use ($handler, $logger, $formatter) {
                // generate id that will be used to supplement the log with information
                $requestId = uniqid('eight_points_guzzle_');

                // initial registration of log
                $logger->info('', compact('request', 'requestId'));

                // this id will be used by RequestTimeMiddleware
                $options['request_id'] = $requestId;

                return $handler($request, $options)->then(

                    function ($response) use ($logger, $request, $formatter, $requestId) {

                        $message = $formatter->format($request, $response);
                        $context = compact('request', 'response', 'requestId');

                        $logger->info($message, $context);

                        return $response;
                    },

                    function ($reason) use ($logger, $request, $formatter, $requestId) {

                        $response = $reason instanceof RequestException ? $reason->getResponse() : null;
                        $message  = $formatter->format($request, $response, $reason);
                        $context  = compact('request', 'response', 'requestId');

                        $logger->notice($message, $context);

                        return \GuzzleHttp\Promise\rejection_for($reason);
                    }
                );
            };
        };
    }
103156
protected function getSlice()
	{
		return function($stack, $pipe)
		{
			return function($passable) use ($stack, $pipe)
			{
				// If the pipe is an instance of a Closure, we will just call it directly but
				// otherwise we'll resolve the pipes out of the container and call it with
				// the appropriate method and arguments, returning the results back out.
				if ($pipe instanceof Closure)
				{
					return call_user_func($pipe, $passable, $stack);
				}
				else
				{
					return $this->container->make($pipe)
							->{$this->method}($passable, $stack);
				}
			};
		};
	}
883073
public function getFilter(): Closure
    {
        $rootDirectory = $this->rootDirectory;
        $includePaths = $this->includePaths;
        $excludePaths = $this->excludePaths;

        return function (SplFileInfo $file) use ($rootDirectory, $includePaths, $excludePaths) {

            if ($file->getExtension() !== 'php') {
                return false;
            }

            $fullPath = $this->getFileFullPath($file);
            // Do not touch files that not under rootDirectory
            if (strpos($fullPath, $rootDirectory) !== 0) {
                return false;
            }

            if (!empty($includePaths)) {
                $found = false;
                foreach ($includePaths as $includePattern) {
                    if (fnmatch("{$includePattern}*", $fullPath, FNM_NOESCAPE)) {
                        $found = true;
                        break;
                    }
                }
                if (!$found) {
                    return false;
                }
            }

            foreach ($excludePaths as $excludePattern) {
                if (fnmatch("{$excludePattern}*", $fullPath, FNM_NOESCAPE)) {
                    return false;
                }
            }

            return true;
        };
    }
1084496
private function doGetReflector()
    {
        switch ($this->getType()) {
            case static::C_TYPE_FUNCTION:
            case static::C_TYPE_CLOSURE:
                return new \ReflectionFunction($this->handler);
            case static::C_TYPE_STATIC_METHOD:
            case static::C_TYPE_INSTANCE_METHOD:
                return new \ReflectionMethod($this->getClass(), $this->getMethod());
            case static::C_TYPE_INVOKED_OBJECT:
                return new \ReflectionMethod($this->getClass(), '__invoke');
            case static::C_TYPE_ERROR:
                throw new \Exception;
                break;
        }
    }