void AbsoluteQuantitation::calculateBiasAndR( const std::vector<AbsoluteQuantitationStandards::featureConcentration> & component_concentrations, const String & feature_name, const String & transformation_model, const Param & transformation_model_params, std::vector<double> & biases, double & correlation_coefficient) { // reset biases biases.clear(); // extract out the calibration points std::vector<double> concentration_ratios, feature_amounts_ratios; TransformationModel::DataPoints data; TransformationModel::DataPoint point; for (size_t i = 0; i < component_concentrations.size(); ++i) { // calculate the actual and calculated concentration ratios double calculated_concentration_ratio = applyCalibration(component_concentrations[i].feature, component_concentrations[i].IS_feature, feature_name, transformation_model, transformation_model_params); double actual_concentration_ratio = component_concentrations[i].actual_concentration/ component_concentrations[i].IS_actual_concentration; concentration_ratios.push_back(component_concentrations[i].actual_concentration); // extract out the feature amount ratios double feature_amount_ratio = calculateRatio(component_concentrations[i].feature, component_concentrations[i].IS_feature, feature_name)/component_concentrations[i].dilution_factor; feature_amounts_ratios.push_back(feature_amount_ratio); // calculate the bias double bias = calculateBias(actual_concentration_ratio, calculated_concentration_ratio); biases.push_back(bias); point.first = actual_concentration_ratio; point.second = feature_amount_ratio; data.push_back(point); } // apply weighting to the feature amounts and actual concentration ratios TransformationModel tm(data, transformation_model_params); tm.weightData(data); std::vector<double> concentration_ratios_weighted, feature_amounts_ratios_weighted; for (size_t i = 0; i < data.size(); ++i) { concentration_ratios_weighted.push_back(data[i].first); feature_amounts_ratios_weighted.push_back(data[i].second); } // calculate the R2 (R2 = Pearson_R^2) correlation_coefficient = Math::pearsonCorrelationCoefficient( concentration_ratios_weighted.begin(), concentration_ratios_weighted.begin() + concentration_ratios_weighted.size(), feature_amounts_ratios_weighted.begin(), feature_amounts_ratios_weighted.begin() + feature_amounts_ratios_weighted.size() ); }
double AbsoluteQuantitation::applyCalibration(const Feature & component, const Feature & IS_component, const String & feature_name, const String & transformation_model, const Param & transformation_model_params) { // calculate the ratio double ratio = calculateRatio(component, IS_component, feature_name); // calculate the absolute concentration TransformationModel::DataPoints data; TransformationDescription tmd(data); // tmd.setDataPoints(data); tmd.fitModel(transformation_model, transformation_model_params); tmd.invert(); double calculated_concentration = tmd.apply(ratio); // AbsoluteQuantitationMethod aqm; // double calculated_concentration = aqm.evaluateTransformationModel( // transformation_model, ratio, transformation_model_params); // check for less than zero if (calculated_concentration < 0.0) { calculated_concentration = 0.0; } return calculated_concentration; }
Param AbsoluteQuantitation::fitCalibration( const std::vector<AbsoluteQuantitationStandards::featureConcentration> & component_concentrations, const String & feature_name, const String & transformation_model, const Param & transformation_model_params) { // extract out the calibration points TransformationModel::DataPoints data; TransformationModel::DataPoint point; for (size_t i = 0; i < component_concentrations.size(); i++) { point.first = component_concentrations[i].actual_concentration/component_concentrations[i].IS_actual_concentration; double ratio = calculateRatio(component_concentrations[i].feature, component_concentrations[i].IS_feature,feature_name); point.second = ratio/component_concentrations[i].dilution_factor; // adjust based on the dilution factor data.push_back(point); } // fit the data to the model TransformationDescription tmd(data); // tmd.setDataPoints(data); tmd.fitModel(transformation_model, transformation_model_params); Param params = tmd.getModelParameters(); // AbsoluteQuantitationMethod aqm; // Param params = aqm.fitTransformationModel(transformation_model, data, transformation_model_params); // store the information about the fit return params; }
BEGIN_JUCE_NAMESPACE //============================================================================== Joystick::Joystick() : Component ("Joystick"), current_x (0), current_y (0), x_min (0), x_max (1), y_min (0), y_max (1), backgroundColour (Colours::black), sendChangeOnlyOnRelease (false), holdOnMouseRelease (false), isVelocityBased (false), menuEnabled (true), menuShown (false), mouseWasHidden (false), numDecimalPlaces (4) { setOpaque (true); setWantsKeyboardFocus (true); calculateRatio(); calculateSnapBack(); }
/** * This implemetation: Interpolate(=blend) Values according to the projected size of the cube sides. * \note The returned value is owned by the caller - you have to remove it! */ GenericAttribute * DirectionalInterpolator::calculateValue(Rendering::RenderingContext & renderingContext, ValuatedRegionNode * vNode, const Frustum & frustum, float measurementApertureAngle_deg/*=90.0*/) { // get values GenericAttribute * values[6]; for(int i=0;i<6;i++){ values[i]=getValueForSide(vNode,static_cast<side_t>(i)); } // get side ratio float ratio[6]; calculateRatio(renderingContext, ratio,frustum,measurementApertureAngle_deg); float sum=0; for(int i=0;i<6;i++){ if(values[i]!=nullptr) sum+=ratio[i]; } // calculate value // todo? blend(genericAttributeList , factors); float value=0; if(sum>0){ for(int i=0;i<6;i++){ if(values[i] == nullptr) continue; value+=values[i]->toFloat()*ratio[i]; } value/=sum; } return GenericAttribute::createNumber(value); }
BEGIN_JUCE_NAMESPACE #include "jucetice_Joystick.h" #include "../../text/juce_LocalisedStrings.h" #include "../../gui/components/menus/juce_PopupMenu.h" //============================================================================== Joystick::Joystick() : Component (T("Joystick")), current_x (0), current_y (0), x_min (0), x_max (1), y_min (0), y_max (1), backgroundColour (Colours::black), sendChangeOnlyOnRelease (false), holdOnMouseRelease (false), isVelocityBased (false), menuEnabled (true), menuShown (false), mouseWasHidden (false), numDecimalPlaces (4) { setOpaque (true); setWantsKeyboardFocus (true); calculateRatio(); calculateSnapBack(); }
FlowContext::FlowContext(FlowBoard *mother, QObject *parent) : QObject(parent), m_board(mother) { connect(m_board, SIGNAL(boardLoaded(int)), this, SLOT(initFlowContext(int))); connect(this, SIGNAL(contextUpdated()), this, SLOT(calculateRatio())); initFlowContext(m_board->getColorCount()); }
//============================================================================== void Joystick::setRanges (const double newHorizontalMin, const double newHorizontalMax, const double newVerticalMin, const double newVerticalMax, const double newInt) { bool horizontalChanged = false; bool verticalChanged = false; if (x_min != newHorizontalMin || x_max != newVerticalMax) { x_min = newHorizontalMin; x_max = newHorizontalMax; horizontalChanged = true; } if (y_min != newVerticalMin || y_max != newVerticalMax) { y_min = newVerticalMin; y_max = newVerticalMax; verticalChanged = true; } // figure out the number of DPs needed to display all values at this // interval setting. interval = newInt; numDecimalPlaces = 7; if (newInt != 0) { int v = abs ((int) (newInt * 10000000)); while ((v % 10) == 0) { --numDecimalPlaces; v /= 10; } } if (horizontalChanged || verticalChanged) setValues (current_x, current_y, false); calculateRatio(); calculateSnapBack(); calculateDrawingSpot(); }