flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chiwanpark <...@git.apache.org>
Subject [GitHub] flink pull request: [Flink-2030][ml]Data Set Statistics and Histog...
Date Sat, 15 Aug 2015 18:26:23 GMT
Github user chiwanpark commented on a diff in the pull request:

    https://github.com/apache/flink/pull/861#discussion_r37137965
  
    --- Diff: flink-staging/flink-ml/src/main/scala/org/apache/flink/ml/statistics/FieldStats.scala
---
    @@ -0,0 +1,119 @@
    +/*
    + * 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.flink.ml.statistics
    +
    +import org.apache.flink.ml.statistics.FieldType._
    +
    +import scala.collection.mutable
    +
    +/** Class to represent Field statistics.
    +  *
    +  * =Parameters=
    +  * -[[fieldType]]:
    +  *   Type of this field, [[DISCRETE]] or [[CONTINUOUS]]
    +  *
    +  * For [[DISCRETE]] fields, [[entropy]], [[gini]] and [[categoryCounts]] are provided.
    +  * For [[CONTINUOUS]] fields, [[min]], [[max]], [[mean]] and [[variance]] are provided.
    +  *
    +  */
    +class FieldStats(val fieldType: FieldType) extends Serializable {
    +  // field parameters
    +  private [statistics] var _min: Double = _
    +  private [statistics] var _max: Double = _
    +  private [statistics] var _mean: Double = _
    +  private [statistics] var _variance: Double = _
    +  private [statistics] var _counts: mutable.HashMap[Double,Int] = _
    +
    +  //-------------------- Access methods ----------------------------//
    +  def min: Double = {
    +    exception(DISCRETE)
    +    _min
    +  }
    +
    +  def max: Double = {
    +    exception(DISCRETE)
    +    _max
    +  }
    +
    +  def mean: Double = {
    +    exception(DISCRETE)
    +    _mean
    +  }
    +
    +  def variance: Double = {
    +    exception(DISCRETE)
    +    _variance
    +  }
    +
    +  def categoryCounts: mutable.HashMap[Double,Int] = {
    +    exception(CONTINUOUS)
    +    _counts
    +  }
    +
    +  /**
    +   * Returns the entropy value for this [[DISCRETE]] field.
    +   */
    +  def entropy: Double = {
    +    exception(CONTINUOUS)
    +    val total: Double = _counts.valuesIterator.sum
    +    3.322 * _counts.iterator.map(x => - (x._2 / total) * Math.log10(x._2 / total)).sum
    --- End diff --
    
    Is 3.322 used for changing base of log from 10 to 2? Why don't you use `Math.log(~~~)
/ Math.log(2)`? Saving `Math.log(2)` into an immutable class member is good for performance.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message