EStatisticValue.java

  1. /*
  2.  * @cond LICENSE
  3.  * ######################################################################################
  4.  * # LGPL License                                                                       #
  5.  * #                                                                                    #
  6.  * # This file is part of the LightJason AgentSpeak(L++)                                #
  7.  * # Copyright (c) 2015-19, LightJason (info@lightjason.org)                            #
  8.  * # This program is free software: you can redistribute it and/or modify               #
  9.  * # it under the terms of the GNU Lesser General Public License as                     #
  10.  * # published by the Free Software Foundation, either version 3 of the                 #
  11.  * # License, or (at your option) any later version.                                    #
  12.  * #                                                                                    #
  13.  * # This program is distributed in the hope that it will be useful,                    #
  14.  * # but WITHOUT ANY WARRANTY; without even the implied warranty of                     #
  15.  * # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                      #
  16.  * # GNU Lesser General Public License for more details.                                #
  17.  * #                                                                                    #
  18.  * # You should have received a copy of the GNU Lesser General Public License           #
  19.  * # along with this program. If not, see http://www.gnu.org/licenses/                  #
  20.  * ######################################################################################
  21.  * @endcond
  22.  */

  23. package org.lightjason.agentspeak.action.builtin.math.statistic;

  24. import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
  25. import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
  26. import org.lightjason.agentspeak.error.CIllegalStateException;

  27. import javax.annotation.Nonnull;
  28. import java.util.Locale;


  29. /**
  30.  * enum of statistic value types
  31.  */
  32. public enum EStatisticValue
  33. {
  34.     GEOMETRICMEAN,
  35.     MAX,
  36.     MIN,
  37.     COUNT,
  38.     POPULATIONVARIANCE,
  39.     QUADRATICMEAN,
  40.     SECONDMOMENT,
  41.     STANDARDDEVIATION,
  42.     SUM,
  43.     SUMLOG,
  44.     SUMSQUARE,
  45.     VARIANCE,
  46.     MEAN,
  47.     KURTIOSIS;

  48.     /**
  49.      * additional factory
  50.      *
  51.      * @param p_value string
  52.      * @return enum
  53.      */
  54.     @Nonnull
  55.     public static EStatisticValue from( @Nonnull final String p_value )
  56.     {
  57.         return EStatisticValue.valueOf( p_value.trim().toUpperCase( Locale.ROOT ) );
  58.     }

  59.     /**
  60.      * returns a statistic value
  61.      *
  62.      * @param p_statistic statistic object
  63.      * @return statistic value
  64.      */
  65.     public final double value( @Nonnull final SummaryStatistics p_statistic )
  66.     {
  67.         switch ( this )
  68.         {
  69.             case GEOMETRICMEAN:
  70.                 return p_statistic.getGeometricMean();

  71.             case MAX:
  72.                 return p_statistic.getMax();

  73.             case MIN:
  74.                 return p_statistic.getMin();

  75.             case COUNT:
  76.                 return p_statistic.getN();

  77.             case POPULATIONVARIANCE:
  78.                 return p_statistic.getPopulationVariance();

  79.             case QUADRATICMEAN:
  80.                 return p_statistic.getQuadraticMean();

  81.             case SECONDMOMENT:
  82.                 return p_statistic.getSecondMoment();

  83.             case STANDARDDEVIATION:
  84.                 return p_statistic.getStandardDeviation();

  85.             case SUM:
  86.                 return p_statistic.getSum();

  87.             case SUMLOG:
  88.                 return p_statistic.getSumOfLogs();

  89.             case SUMSQUARE:
  90.                 return p_statistic.getSumsq();

  91.             case VARIANCE:
  92.                 return p_statistic.getVariance();

  93.             case MEAN:
  94.                 return p_statistic.getMean();

  95.             default:
  96.                 throw new CIllegalStateException( org.lightjason.agentspeak.common.CCommon.languagestring( this, "unknown", this ) );
  97.         }
  98.     }

  99.     /**
  100.      * returns a statistic value
  101.      *
  102.      * @param p_statistic statistic object
  103.      * @return statistic value
  104.      */
  105.     public final double value( @Nonnull final DescriptiveStatistics p_statistic )
  106.     {
  107.         switch ( this )
  108.         {
  109.             case GEOMETRICMEAN:
  110.                 return p_statistic.getGeometricMean();

  111.             case MAX:
  112.                 return p_statistic.getMax();

  113.             case MIN:
  114.                 return p_statistic.getMin();

  115.             case COUNT:
  116.                 return p_statistic.getN();

  117.             case POPULATIONVARIANCE:
  118.                 return p_statistic.getPopulationVariance();

  119.             case QUADRATICMEAN:
  120.                 return p_statistic.getQuadraticMean();

  121.             case STANDARDDEVIATION:
  122.                 return p_statistic.getStandardDeviation();

  123.             case SUM:
  124.                 return p_statistic.getSum();

  125.             case SUMSQUARE:
  126.                 return p_statistic.getSumsq();

  127.             case VARIANCE:
  128.                 return p_statistic.getVariance();

  129.             case MEAN:
  130.                 return p_statistic.getMean();

  131.             case KURTIOSIS:
  132.                 return p_statistic.getKurtosis();

  133.             default:
  134.                 throw new CIllegalStateException( org.lightjason.agentspeak.common.CCommon.languagestring( this, "unknown", this ) );
  135.         }
  136.     }
  137. }