|
| 1 | +// |
| 2 | +// BEMGraphCalculator.h |
| 3 | +// SimpleLineChart |
| 4 | +// |
| 5 | +// Created by Sam Spencer on 1/26/16. |
| 6 | +// Copyright © 2016 Boris Emorine. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +@import Foundation; |
| 10 | + |
| 11 | +#import "BEMSimpleLineGraphView.h" |
| 12 | + |
| 13 | +/** There are multiple ways to find the area under the curve of a graph; \p BEMIntegrationMethod describes available methods for calculating this area. |
| 14 | + @discussion Finding the area under the curve of a graph becomes especially useful when charting rate over time. For example, finding the area of a graph that displays the speed of a cyclist at certain times would produce the total distance the cyclist traveled. |
| 15 | + @abstract Integration is a concept in calculus allowing one to find the area under a curve. However, integration requires manipulating the function of a graph. Because \p BEMSimpleLineGraphView objects rely on data points and not functions, other area-finding methods (with varying levels of accuracy) are employed here. |
| 16 | + @note As a general rule, the more accurate an integration method, the more computationally intense it may be. */ |
| 17 | +typedef NS_ENUM (NSInteger, BEMIntegrationMethod) { |
| 18 | + /// Calculates area by finding the sum of all left–hand rectangles under each data point. This method gives the exact area when the graph's curve is constant. Low intensity computation. |
| 19 | + BEMIntegrationMethodLeftReimannSum = 0, |
| 20 | + /// Calculates area by finding the sum of all right–hand rectangles under each data point. This method gives the exact area when the graph's curve is constant. Low intensity computation. |
| 21 | + BEMIntegrationMethodRightReimannSum = 1, |
| 22 | + /// Calculates area by finding the sum of all trapezoids under each data point. This method gives the exact area when the graph's curve is constant or linear. Moderate intensity computation. |
| 23 | + BEMIntegrationMethodTrapezoidalSum = 2, |
| 24 | + /// Calculates area by finding the sum of all parabolas under each data point. This method gives the exact area when the graph's curve is constant, linear, quadratic, or cubic. Moderate intensity computation. |
| 25 | + BEMIntegrationMethodParabolicSimpsonSum = 3 |
| 26 | +}; |
| 27 | + |
| 28 | +/** There are multiple methods to determine the correlation between points on a graph; \p BEMCorrelationMethod describes available methods for determining this coefficient. |
| 29 | + @discussion Discussion on data correlation to be added. |
| 30 | + @abstract Abstract on data correlation to be added. |
| 31 | + @note The greater the number of points on the given graph, the longer it may take to determine a correlation for those points. */ |
| 32 | +typedef NS_ENUM (NSInteger, BEMCorrelationMethod) { |
| 33 | + /// Calculates the correlation coefficent for the graph using the common Pearson Correlation Method. |
| 34 | + BEMCorrelationMethodPearson = 0 |
| 35 | +}; |
| 36 | + |
| 37 | +/** When calculating a correlation coefficient with the Pearson Correlation Method, \p BEMGraphCalculator can provide more general feedback as to the strength of the correlation. */ |
| 38 | +typedef NS_ENUM (NSInteger, BEMPearsonCorrelationStrength) { |
| 39 | + /// Positive correlation value: 1.00 : 0.95 |
| 40 | + BEMPearsonCorrelationPerfectPositive = 0, |
| 41 | + /// Positive correlation value: 0.94 : 0.50 |
| 42 | + BEMPearsonCorrelationStrongPositive = 1, |
| 43 | + /// Positive correlation value: 0.49 : 0.06 |
| 44 | + BEMPearsonCorrelationWeakPositive = 2, |
| 45 | + /// Positive correlation value: 0.05 : -0.05 |
| 46 | + BEMPearsonCorrelationNone = 3, |
| 47 | + /// Positive correlation value: -0.06 : -0.49 |
| 48 | + BEMPearsonCorrelationWeakNegative = 4, |
| 49 | + /// Positive correlation value: -0.50 : -0.94 |
| 50 | + BEMPearsonCorrelationStrongNegative = 5, |
| 51 | + /// Positive correlation value: -0.95 : -1.00 |
| 52 | + BEMPearsonCorrelationPerfectNegative = 6 |
| 53 | +}; |
| 54 | + |
| 55 | + |
| 56 | +NS_ASSUME_NONNULL_BEGIN |
| 57 | + |
| 58 | +/** Makes calculations given for a specific graph object. |
| 59 | + @discussion Supply a graph object to the calculator to perform operations with that graph's data. Calculations may include the following: |
| 60 | + - Average value of points |
| 61 | + - Sum of points |
| 62 | + - Median of points |
| 63 | + - Mode of points |
| 64 | + - Graph standard deviation |
| 65 | + - Minimum point value on graph |
| 66 | + - Maximum point value on graph |
| 67 | + - Area under the curve of a graph |
| 68 | + - Correlation of data points */ |
| 69 | +@interface BEMGraphCalculator : NSObject |
| 70 | + |
| 71 | ++ (BEMGraphCalculator *)sharedCalculator; |
| 72 | + |
| 73 | +/** Calculates the average (mean) of all points on the line graph. |
| 74 | + @return The average (mean) number of the points on the graph. Originally a float. */ |
| 75 | +- (NSNumber *)calculatePointValueAverageOnGraph:(BEMSimpleLineGraphView *)graph; |
| 76 | + |
| 77 | + |
| 78 | +/** Calculates the sum of all points on the line graph. |
| 79 | + @return The sum of the points on the graph. Originally a float. */ |
| 80 | +- (NSNumber *)calculatePointValueSumOnGraph:(BEMSimpleLineGraphView *)graph; |
| 81 | + |
| 82 | + |
| 83 | +/** Calculates the median of all points on the line graph. |
| 84 | + @return The median number of the points on the graph. Originally a float. */ |
| 85 | +- (NSNumber *)calculatePointValueMedianOnGraph:(BEMSimpleLineGraphView *)graph; |
| 86 | + |
| 87 | + |
| 88 | +/** Calculates the mode of all points on the line graph. |
| 89 | + @return The mode number of the points on the graph. Originally a float. */ |
| 90 | +- (NSNumber *)calculatePointValueModeOnGraph:(BEMSimpleLineGraphView *)graph; |
| 91 | + |
| 92 | + |
| 93 | +/** Calculates the standard deviation of all points on the line graph. |
| 94 | + @return The standard deviation of the points on the graph. Originally a float. */ |
| 95 | +- (NSNumber *)calculateStandardDeviationOnGraph:(BEMSimpleLineGraphView *)graph; |
| 96 | + |
| 97 | + |
| 98 | +/** Calculates the minimum value of all points on the line graph. |
| 99 | + @return The minimum number of the points on the graph. Originally a float. */ |
| 100 | +- (NSNumber *)calculateMinimumPointValueOnGraph:(BEMSimpleLineGraphView *)graph; |
| 101 | + |
| 102 | + |
| 103 | +/** Calculates the maximum value of all points on the line graph. |
| 104 | + @return The maximum value of the points on the graph. Originally a float. */ |
| 105 | +- (NSNumber *)calculateMaximumPointValueOnGraph:(BEMSimpleLineGraphView *)graph; |
| 106 | + |
| 107 | + |
| 108 | +/** Calculates the area under the curve of the graph. |
| 109 | + @return The area under the curve of the graph. Accuracy varies based on selected integration method. Originally a float. */ |
| 110 | +- (NSNumber *)calculateAreaUsingIntegrationMethod:(BEMIntegrationMethod)integrationMethod onGraph:(BEMSimpleLineGraphView *)graph xAxisScale:(NSNumber *)scale; |
| 111 | + |
| 112 | + |
| 113 | +/** Calculates a correlation coefficient for the data points on the graph. |
| 114 | + @return A correlation coefficient, calculated from the graph's data points. Float value between -1.0 and 1.0. A value of -1.0 is a perfect negative correlation. A value of 1.0 is a perfect positive correlation. A value of 0.0 means that no correlation exists. */ |
| 115 | +- (NSNumber *)calculateCorrelationCoefficientUsingCorrelationMethod:(BEMCorrelationMethod)correlationMethod onGraph:(BEMSimpleLineGraphView *)graph xAxisScale:(nonnull NSNumber *)scale; |
| 116 | + |
| 117 | + |
| 118 | +/** Calculates a correlation coefficient and returns the general strength of the correlation, based on the data points on the given graph object. |
| 119 | + @return The strength of the calculated correlation coefficient; calculated from the graph's data points. This method assumes the Pearson Correlation Method. */ |
| 120 | +- (BEMPearsonCorrelationStrength)calculatePearsonCorrelationStrengthOnGraph:(BEMSimpleLineGraphView *)graph xAxisScale:(nonnull NSNumber *)scale; |
| 121 | + |
| 122 | + |
| 123 | +/** Calculates a correlation coefficient and returns the general strength of the correlation, based on the data points on the given graph object. |
| 124 | + @return The strength of the calculated correlation coefficient; calculated from the graph's data points. This method assumes the Pearson Correlation Method. */ |
| 125 | +- (BEMPearsonCorrelationStrength)calculatePearsonCorrelationStrengthOnGraph:(BEMSimpleLineGraphView *)graph; |
| 126 | + |
| 127 | +@end |
| 128 | + |
| 129 | +NS_ASSUME_NONNULL_END |
0 commit comments