Github user jkbradley commented on a diff in the pull request:

    https://github.com/apache/spark/pull/2451#discussion_r17807758
  
    --- Diff: 
mllib/src/main/scala/org/apache/spark/mllib/optimization/Gradient.scala ---
    @@ -157,3 +157,221 @@ class HingeGradient extends Gradient {
         }
       }
     }
    +
    +/**
    + * :: DeveloperApi ::
    + * Class used to compute the gradient for a loss function, given a series 
of data points.
    + */
    +@DeveloperApi
    +abstract class MultiModelGradient extends Serializable {
    +  /**
    +   * Compute the gradient and loss given the features of all data points.
    +   *
    +   * @param data features for one data point
    +   * @param label label for this data point
    +   * @param weights weights/coefficients corresponding to features
    +   *
    +   * @return (gradient: DenseMatrix, loss: Double)
    +   */
    +  def compute(data: Matrix, label: DenseMatrix,
    +                       weights: DenseMatrix): (DenseMatrix, Matrix)
    +
    +  /**
    +   * Compute the gradient and loss given the features of a series of data 
point,
    +   * add the gradient to a provided matrix to avoid creating new objects, 
and return loss.
    +   *
    +   * @param data features for the data points
    +   * @param label label for the data points
    +   * @param weights weights/coefficients corresponding to features
    +   * @param cumGradient the computed gradient will be added to this matrix
    +   *
    +   * @return loss
    +   */
    +  def compute(data: Matrix, label: DenseMatrix,
    +                       weights: DenseMatrix, cumGradient: DenseMatrix): 
Matrix
    +}
    +
    +/**
    + * :: DeveloperApi ::
    + * Compute gradient and loss for a logistic loss function, as used in 
binary classification.
    + * See also the documentation for the precise formulation.
    + */
    +@DeveloperApi
    +class MultiModelLogisticGradient extends MultiModelGradient {
    +
    +  private def sigmoid(p: DenseMatrix): DenseMatrix = {
    +    def takeSigmoid(p: Double): Double = {
    +      1.0 / (math.exp(-p) + 1.0)
    +    }
    +    p.map(takeSigmoid)
    +  }
    +
    +  override def compute(data: Matrix, label: DenseMatrix,
    --- End diff --
    
    Can this be implemented using the below compute method to avoid code 
duplication?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to