[ 
https://issues.apache.org/jira/browse/MAHOUT-1856?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15837955#comment-15837955
 ] 

ASF GitHub Bot commented on MAHOUT-1856:
----------------------------------------

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

    https://github.com/apache/mahout/pull/246#discussion_r97809121
  
    --- Diff: 
math-scala/src/main/scala/org/apache/mahout/math/algorithms/regression/CochraneOrcutt.scala
 ---
    @@ -0,0 +1,89 @@
    +/**
    +  * Licensed to the Apache Software Foundation (ASF) under one
    +  * or more contributor license agreements. See the NOTICE file
    +  * distributed with this work for additional information
    +  * regarding copyright ownership. The ASF licenses this file
    +  * to you under the Apache License, Version 2.0 (the
    +  * "License"); you may not use this file except in compliance
    +  * with the License. You may obtain a copy of the License at
    +  *
    +  * http://www.apache.org/licenses/LICENSE-2.0
    +  *
    +  * Unless required by applicable law or agreed to in writing,
    +  * software distributed under the License is distributed on an
    +  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +  * KIND, either express or implied. See the License for the
    +  * specific language governing permissions and limitations
    +  * under the License.
    +  */
    +
    +package org.apache.mahout.math.algorithms.regression
    +
    +import org.apache.mahout.math.{Vector => MahoutVector}
    +import org.apache.mahout.math.drm.CacheHint
    +import org.apache.mahout.math.drm.DrmLike
    +import org.apache.mahout.math.drm.RLikeDrmOps._
    +import org.apache.mahout.math.scalabindings.RLikeOps._
    +
    +class CochraneOrcutt[K](hyperparameters: (Symbol, Any)*) extends 
LinearRegressor[K] {
    +  // https://en.wikipedia.org/wiki/Cochrane%E2%80%93Orcutt_estimation
    +
    +  var regressor: LinearRegressor[K] = 
hyperparameters.asInstanceOf[Map[Symbol, 
LinearRegressor[K]]].getOrElse('regressor, new OrdinaryLeastSquares())
    +  var iterations: Int = hyperparameters.asInstanceOf[Map[Symbol, 
Int]].getOrElse('iterations, 3)
    +  var cacheHint: CacheHint.CacheHint = 
hyperparameters.asInstanceOf[Map[Symbol, 
CacheHint.CacheHint]].getOrElse('cacheHint, CacheHint.MEMORY_ONLY)
    +  // For larger inputs, CacheHint.MEMORY_AND_DISK2 is reccomended.
    +
    +  var betas: Array[MahoutVector] = _
    +
    +  var summary = ""
    +
    +  setHyperparameters(hyperparameters.toMap)
    +
    +  def setHyperparameters(hyperparameters: Map[Symbol, Any] = Map('foo -> 
None)): Unit = {
    +    regressor = hyperparameters.asInstanceOf[Map[Symbol, 
LinearRegressor[K]]].getOrElse('regressor, new OrdinaryLeastSquares())
    +    iterations = hyperparameters.asInstanceOf[Map[Symbol, 
Int]].getOrElse('iterations, 3)
    +    cacheHint = hyperparameters.asInstanceOf[Map[Symbol, 
CacheHint.CacheHint]].getOrElse('cacheHint, CacheHint.MEMORY_ONLY)
    +  }
    +
    +  def fit(drmFeatures: DrmLike[K], drmTarget: DrmLike[K], hyperparameters: 
(Symbol, Any)*): Unit = {
    +
    +    var hyperparameters: Option[Map[String,Any]] = None
    +    betas = new Array[MahoutVector](iterations)
    +    regressor.fit(drmFeatures, drmTarget)
    +    betas(0) = regressor.beta
    +
    +    drmY = drmTarget
    +
    +    val Y = drmTarget(1 until drmTarget.nrow.toInt, 0 until 
1).checkpoint(cacheHint)
    +    val Y_lag = drmTarget(0 until drmTarget.nrow.toInt - 1, 0 until 
1).checkpoint(cacheHint)
    +    val X = drmFeatures(1 until drmFeatures.nrow.toInt, 0 until 
1).checkpoint(cacheHint)
    +    val X_lag = drmFeatures(0 until drmFeatures.nrow.toInt - 1, 0 until 
1).checkpoint(cacheHint)
    --- End diff --
    
    missed all of these- but have since updated with `safeToNonNegInt(`


> Create a framework for new Mahout Clustering, Classification, and 
> Optimization  Algorithms
> ------------------------------------------------------------------------------------------
>
>                 Key: MAHOUT-1856
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-1856
>             Project: Mahout
>          Issue Type: New Feature
>    Affects Versions: 0.12.1
>            Reporter: Andrew Palumbo
>            Assignee: Trevor Grant
>            Priority: Critical
>             Fix For: 0.13.0
>
>
> To ensure that Mahout does not become "A loose bag of algorithms", Create 
> basic traits with funtions common to each class of algorithm. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to