Example #1
0
void AndroidTransformAnimation::applyForProgress(LayerAndroid* layer, float progress)
{
    // First, we need to get the from and to values
    int from, to;
    pickValues(progress, &from, &to);

    TransformAnimationValue* fromValue = (TransformAnimationValue*) m_operations->at(from);
    TransformAnimationValue* toValue = (TransformAnimationValue*) m_operations->at(to);

    ALOGV("[layer %d] fromValue %x, key %.2f, toValue %x, key %.2f for progress %.2f",
          layer->uniqueId(),
          fromValue, fromValue->keyTime(),
          toValue, toValue->keyTime(), progress);

    // We now have the correct two values to work with, let's compute the
    // progress value

    const TimingFunction* timingFunction = fromValue->timingFunction();
    float p = applyTimingFunction(fromValue->keyTime(), toValue->keyTime(),
                                  progress, timingFunction);
    ALOGV("progress %.2f => %.2f from: %.2f to: %.2f", progress, p, fromValue->keyTime(),
          toValue->keyTime());
    progress = p;

    // With both values and the progress, we also need to check out that
    // the operations are compatible (i.e. we are animating the same number
    // of values; if not we do a matrix blend)

    TransformationMatrix transformMatrix;
    bool valid = true;
    unsigned int fromSize = fromValue->value()->size();
    if (fromSize) {
        if (toValue->value()->size() != fromSize)
            valid = false;
        else {
            for (unsigned int j = 0; j < fromSize && valid; j++) {
                if (!fromValue->value()->operations()[j]->isSameType(
                    *toValue->value()->operations()[j]))
                    valid = false;
            }
        }
    }

    IntSize size(layer->getSize().width(), layer->getSize().height());
    if (valid) {
        for (size_t i = 0; i < toValue->value()->size(); ++i)
            toValue->value()->operations()[i]->blend(fromValue->value()->at(i),
                                                     progress)->apply(transformMatrix, size);
    } else {
        TransformationMatrix source;

        fromValue->value()->apply(size, source);
        toValue->value()->apply(size, transformMatrix);

        transformMatrix.blend(source, progress);
    }

    // Set the final transform on the layer
    layer->setTransform(transformMatrix);
}
Example #2
0
void AndroidOpacityAnimation::applyForProgress(LayerAndroid* layer, float progress)
{
    // First, we need to get the from and to values
    int from, to;
    pickValues(progress, &from, &to);
    FloatAnimationValue* fromValue = (FloatAnimationValue*) m_operations->at(from);
    FloatAnimationValue* toValue = (FloatAnimationValue*) m_operations->at(to);

    ALOGV("[layer %d] opacity fromValue %x, key %.2f, toValue %x, key %.2f for progress %.2f",
          layer->uniqueId(),
          fromValue, fromValue->keyTime(),
          toValue, toValue->keyTime(), progress);

    // We now have the correct two values to work with, let's compute the
    // progress value

    const TimingFunction* timingFunction = fromValue->timingFunction();
    progress = applyTimingFunction(fromValue->keyTime(), toValue->keyTime(),
                                   progress, timingFunction);


    float value = fromValue->value() + ((toValue->value() - fromValue->value()) * progress);

    layer->setOpacity(value);
}
Example #3
0
void SolverPCA::getAnaliticAverage()
{
    double *mass; // массив значений концентраций для компонента
    QHash<QString,unsigned int>::iterator iterator;
//    ItemInSample item_1;
    double average = 0; // средняя концентрация для компонента по анализируемым пробам
    QVector<double> vec_values;
    int length = 0; // длина массива для нахождения среднего и диспесрисии
//    QHash<unsigned int, ItemInSample> *items_in_sample = new QHash<unsigned int, ItemInSample>();

    // для всех компонентов находится среднее по анализируемомму типу вод
    for (iterator = Names::params->begin(); iterator != Names::params->end(); iterator ++)
    {
        length = 0;
        average = 0;

        // получить все значения концентраций компонента для анализируемого типа вод
        vec_values = pickValues(iterator.value(),Names::analitic_id);
        length = vec_values.size();
        mass = new double [length];

        // преобразование вектора значений в массив
        for (int i = 0; i < length; i ++)
        {
            mass[i] = vec_values[i];
        }

        // определение среднего для компонента в пробах анализируемого типа
        average = getAverage(mass, length);
        qDebug()<<"item name: "<<iterator.key()<<" | item average: "<< average;
        analitic_average->insert(iterator.value(),average);
    }

}
Example #4
0
void SolverPCA::standart()
{
    double *mass;
    QHash<QString,unsigned int>::iterator iterator;
    ItemInSample item_1;
    double average = 0; // среднее для компонента по анализируемым пробам (всегда, так определена стандартизация)
    double norm = 0; // дисперсия для значений компонента
    double res = 0; // стандартизированное значение
    int length = 0; // длина массива концентраций компонента для проб определенного типа
    QVector<double> vec_values;
    QVector<Sample*> water_samples;
    QHash<unsigned int, ItemInSample> *items_in_sample = new QHash<unsigned int, ItemInSample>();
    QHash<QString,unsigned int>::iterator water_id;

    pickSamples();
    getAnaliticAverage();

    for (water_id = Names::water_types->begin(); water_id != Names::water_types->end(); water_id ++)
    {
        water_samples = samples_by_type.value(water_id.value());
//        qDebug()<<"water_name: "<<water_id.key();
//        qDebug()<<"size: "<< water_samples.size();
        for (iterator = Names::params->begin(); iterator != Names::params->end(); iterator ++)
        {
//            qDebug()<<"name: "<< iterator.key();
            average = analitic_average->value(iterator.value());
            vec_values = pickValues(iterator.value(),water_id.value());
            length = vec_values.size();
            mass = new double [length];

            for (int i = 0; i < length; i ++)
            {
                mass[i] = vec_values[i];
            }

            // определение коэффициента нормирования
            norm = getAverageSquare(mass, average, mass, average, length);// / length;
//            qDebug()<<"cov: "<< sqrt(norm);

            //стандартизация концентраций компонента во всех пробах типа water_id
            for (int i = 0; i < water_samples.size(); i ++)
            {
                items_in_sample = water_samples[i]->getComponents();
                if (items_in_sample->contains(iterator.value()))
                {
                    // получение текущего значения концентрации и стандартизация его,
                    // после чего запись обратно в пробу
                    item_1 = items_in_sample->value(iterator.value());
                    res = (item_1.getValue() - average) / sqrt(norm);//
//                    qDebug()<<"res: "<<res;
                    item_1.setValue(res);
                    water_samples[i]->getComponents()->insert(iterator.value(),item_1);
                }
            }

        }// for (iterator = Names::params->begin(); iterator != Names::params->end(); iterator ++)
        samples_by_type.insert(water_id.value(),water_samples);

    } // for (water_id = Names::water_types->begin(); water_id != Names::water_types->end(); water_id ++)
}
Example #5
0
QVector<SampleInfo> SolverPCA::getSamplesInfo(unsigned int *items_set, unsigned int water_id)
{
    double** scores_matrix; // матрица счетов для текущего набора. Для каждого источника своя матрица
    double** loads_matrix; // матрица нагрузок для текущего набора
    QVector<Sample*> samples; // проба для типа вод
    QMap<unsigned int, QVector<Sample*> >::iterator wt_iter;
    QVector<double> vec_item_value;
//    double *container;
    double first = 0; // первый столбец дял матрицы счетов
    double second = 0;// второй столбец дял матрицы счетов
    QString str = ""; // строка для вывода в дебаг
    QVector<SampleInfo> points; // список проб с информацией о дате, месте отбора, об источнике и положение пробы в координатах u1 и u2
    AnaliticPoints analitic_points;
//    SpringPoints spring_points;



    loads_matrix = complete_plurals.value(items_set);
    wt_iter = samples_by_type.find(water_id);
//    for (wt_iter = samples_by_type.begin(); wt_iter != samples_by_type.end(); wt_iter ++)
//    {
        samples = wt_iter.value();
        qDebug()<<"Samples.size(): "<<samples.size();

        // сбор информации о пробах
        for (int i = 0; i < samples.size(); i ++)
        {
            SampleInfo si;
            si.setDate(samples[i]->getDate());
            si.setLocationId(samples[i]->getLocationId());
            si.setWaterId(samples[i]->getWaterId());
            points.append(si);
        }
//        container = new double[size * samples.size() + size];
        scores_matrix = new double*[samples.size()];
//        loads_matrix = complete_plurals.find(items_set).value();
        double matrix[samples.size()][size];

        for (int row_ind = 0; row_ind < samples.size(); row_ind ++)
        {

            // создать массив данных для проведения метода PCA
            // Container заполняется согласно тому как будет разбираться в real_2d_array.setcontainer()
            // цикл по количеству компонентов в наборе (особенность создания контейнера)
            for (int col_ind = 0; col_ind < size; col_ind ++)
            {
                vec_item_value = pickValues(items_set[col_ind], water_id);

                matrix[row_ind][col_ind] = vec_item_value[row_ind];
            }
        }




         for (int i = 0; i < samples.size(); i ++)
         {
             scores_matrix[i] = new double [2];
             first = 0;
             second = 0;
             for (int j = 0; j < size; j ++)
             {
//                 qDebug()<<"matrix[i][j]:" << matrix[i][j];
//                 qDebug()<<"loads_matrix[j][0]: "<<loads_matrix[j][0];
//                 qDebug()<<"loads_matrix[j][1]: "<<loads_matrix[j][1];
                 first += matrix[i][j]*loads_matrix[j][0];
                 second += matrix[i][j]*loads_matrix[j][1];
             }
             scores_matrix[i][0] = first;
             scores_matrix[i][1] = second;
         }
         // запись координат точки
         for (int i = 0; i < samples.size(); i ++)
         {
             points[i].setU1(scores_matrix[i][0]);
             points[i].setU2(scores_matrix[i][1]);
         }
//         qDebug()<<"------------------------------------------";
//         qDebug()<<"loads";
//                  for (int i = 0; i < samples.size(); i ++)
//                  {
//                      str = "";
//                      for (int j = 0; j < size; j ++)
//                      {
//                          str += QString("%1 ").arg(loads_matrix[i][j]);
//                      }
//                      qDebug()<<str;
//                  }
//         qDebug()<<"Scores";
//         for (int i = 0; i < samples.size(); i ++)
//         {
//             str = "";
////             for (int j = 0; j < size; j ++)
////             {
//                 str = QString("%1 %2").arg(scores_matrix[i][0]).arg(scores_matrix[i][1]);
////             }
//             qDebug()<<str;
//         }
         return points;

//        for (int)
//    }

//    samples =
}
Example #6
0
void SolverPCA::lookForCompletePlurals()
{



//    qDebug()<<"plurals count: "<<plurals.size();
    // цикл по всем сгенерированным множествам
    clock_t start;
    clock_t end;
    start = clock();
//    int plur_count = 0;
    long int all = 0;
    omp_set_num_threads(6);
#pragma omp parallel
    {
#pragma omp for
    for (int plural_ind = 0; plural_ind < plurals.size(); plural_ind ++)
    {
//        qDebug()<<"thread id: "<< omp_get_thread_num();
        alglib::real_2d_array dataset; // матрица данных для проведения pca
        alglib::real_2d_array res_dataset; // матрица нагрузок
        alglib::real_1d_array variars; // массив весов компонентов
        alglib::ae_int_t rows; // число строк в матрице данных
        alglib::ae_int_t cols; // число столбцов в матрице данных
        alglib::ae_int_t info;
        QVector<Sample*> analitic_samples;
        int analitic_count = 0;

        double *container;
        double first_component = 0; // нагрузка на первую компоненту
        double second_component = 0; // нагрузка на вторую компоненту
        double sum_w = 0; // сумма весов компонентов

        double **loading_matrix; // матрица нагрузок для подходящего набора
        QVector<double> vec_item_value;


        analitic_samples = samples_by_type.value(Names::analitic_id);
        analitic_count = analitic_samples.size();
        /*container = new double[size * analitic_count];*/// + size];
        rows = analitic_count;
        cols = size;
        info = 0;

        container = new double[size * analitic_count + size];
        //цикл по все пробам для сбора значений концентрации компонента
        for (int row_ind = 0; row_ind < analitic_count; row_ind ++)
        {
            // создать массив данных для проведения метода PCA
            // Container заполняется согласно тому как будет разбираться в real_2d_array.setcontainer()
            // цикл по количеству компонентов в наборе (особенность создания контейнера)
            for (int col_ind = 0; col_ind < size; col_ind ++)
            {
                vec_item_value = pickValues(plurals[plural_ind][col_ind], Names::analitic_id);
                container[row_ind * size + col_ind] = vec_item_value[row_ind];
//                item_value_iterator = item_values.find(plurals[plural_ind][col_ind]);
//                container[row_ind * size + col_ind] = item_value_iterator.value()[row_ind];
            }
        }

        QString str = "";
       // подготовка массива данных
       dataset.setcontent(rows, cols, container);
//       delete container;

            //метод PCA
            alglib::pcabuildbasis(dataset, rows, cols, info, variars, res_dataset);
#pragma omp atomic
            all ++;
            sum_w = 0;
            first_component = 0;
            second_component = 0;
            for (int i = 0; i < variars.length(); i ++)
            {
                sum_w += variars(i);
            }
            first_component = variars(0) / sum_w;
            second_component = variars(1) / sum_w;

            qDebug()<<"checked: "<<all;
            if ((first_component + second_component) > 0.9)
            {

//               plur_count ++;
//               qDebug()<<"complete count: "<< plur_count;

                // преобрахование матрицы нагрузок из типа alglib::real_2d_array в double**
                loading_matrix = new double*[res_dataset.rows()];
                for (int i = 0; i < variars.length(); i ++)
                           {
                               sum_w += variars(i);
                           }

                for (int i = 0; i < res_dataset.rows(); i ++)
                {
                    loading_matrix[i] = new double[res_dataset.cols()];
                    for (int j = 0; j < res_dataset.cols(); j ++)
                    {
                        loading_matrix[i][j] = res_dataset[i][j];
                    }
                }
#pragma omp critical
                {
                complete_plurals.insert(plurals[plural_ind],loading_matrix);
                }
//                getScores(plurals[plural_ind]);
            }// if ((first_component + second_component) > 0.9)
delete container;
    }// for (int plural_ind = 0; plural_ind < plurals.size(); plural_ind ++)
    }
    end = clock() - start;
    qDebug()<< "executing time: "<<(end / CLOCKS_PER_SEC);
    qDebug()<<"complete count: "<<complete_plurals.size();




}