Ejemplo n.º 1
0
void testBaumwelch(int seqlen){

  int  error;
 
  ghmm_dmodel * mo_gen = NULL;
  ghmm_dmodel * mo_time = NULL;
  ghmm_dmodel * mo_mem  = NULL;
  ghmm_dseq * my_output = NULL;
   

  if (!(mo_gen = malloc (sizeof (ghmm_dmodel))))
    {printf ("malloc failed in line %d", __LINE__); exit(1);}
  if (!(mo_time = malloc (sizeof (ghmm_dmodel))))
    {printf ("malloc failed in line %d", __LINE__); exit(1);}
  if (!(mo_mem = malloc (sizeof (ghmm_dmodel))))
    {printf ("malloc failed in line %d", __LINE__); exit(1);}
      
  /* generate a model with variable number of states*/
  generateModel(mo_gen,  7, 92304);
  generateModel(mo_time, 5, 1704);
  generateModel(mo_mem,  5, 1704);

  /*generate a random sequence*/
  my_output = ghmm_dmodel_label_generate_sequences(mo_gen, 0, seqlen, NR_SEQUENCES, seqlen);
  /* ghmm_dmodel_add_noise(mo_time, .499, 0); */
  /* randomize the second */
  /* ghmm_dmodel_add_noise(mo_mem, .499, 0); */

  ghmm_dmodel_print(stdout, mo_time);
  ghmm_dmodel_print(stdout, mo_mem);
  printf("Distance between the two models: %g\n\n", ghmm_dmodel_distance(mo_time, mo_mem));

  /* shifting both models in diffrent directions */
  /* train the first */	 
  /*ghmm_dmodel_label_baum_welch(mo_time, my_output);*/
  error = ghmm_dmodel_baum_welch(mo_time, my_output);

  /* train the second and hope they are equal */
  error = ghmm_dmodel_baum_welch(mo_mem, my_output);

  ghmm_dmodel_print(stdout, mo_time);
  ghmm_dmodel_print(stdout, mo_mem);
  printf("Distance between the two trained models: %g\n", ghmm_dmodel_distance(mo_time, mo_mem));

  printf("Log-Likelyhood generating:    %g\n", ghmm_dmodel_likelihood (mo_gen, my_output));
  printf("Log-Likelyhood fb-Baum-Welch: %g\n", ghmm_dmodel_likelihood (mo_time, my_output));
  printf("Log-Likelyhood me-Baum-Welch: %g\n", ghmm_dmodel_likelihood (mo_mem, my_output));


  /* freeing memory */
  ghmm_dmodel_free(&mo_gen);
  ghmm_dmodel_free(&mo_time);
  ghmm_dmodel_free(&mo_mem);
  
  ghmm_dseq_free(&my_output);
}
Ejemplo n.º 2
0
void PluginGame5GenerateSituationDialog::onClickOk()
{
    rdo::gui::model::Model* pModel = getCurrentModel();
    generateModel();
    pModel->runModel();
    done(Accepted);
}
void milxQtDiffusionTensorModel::harmonics(QString ordersString)
{
    bool ok = false;
    if(ordersString.isEmpty())
    {
        ordersString = QInputDialog::getText(this, tr("Enter order magnitudes of harmonics separated by spaces"),
                                            tr("Orders: "), QLineEdit::Normal,
                                            "1 0 0 0 1 1 1 1 1", &ok);
    }
    if (!ok || ordersString.isEmpty())
        return;

    QStringList orders = ordersString.split(" ");
    std::vector<double> sHarmonicCoefficients;
    for(int i = 0; i < orders.size(); i++)
        sHarmonicCoefficients.push_back(orders[i].toDouble());

    int n_coefs = sHarmonicCoefficients.size();
    int l_max   = milxQtDiffusionTensorModel::LforN( n_coefs );

    vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
        sphereSource->SetThetaResolution( 64 );
        sphereSource->SetPhiResolution( 64 );
        sphereSource->SetRadius( 1.0 );
        sphereSource->Update();
    vtkSmartPointer<vtkPolyData> glyph = sphereSource->GetOutput();

    ///For every point in sphere mesh
    double m_x = 0, m_y = 0, m_z = 0;
    for(int i = 0; i < glyph->GetNumberOfPoints(); i++)
    {
        double point_sphere[3];
        glyph->GetPoint(i, point_sphere);
        double x_s = point_sphere[0];
        double y_s = point_sphere[1];
        double z_s = point_sphere[2];

        double x_g, y_g, z_g;

        ///Compute spherical harmonic amplitude
        double amplitude = computeAmplitude( sHarmonicCoefficients, x_s, y_s, z_s, l_max );

        if(amplitude < 0)
            amplitude = 0;

        ///use this to displace sphere points accordingly
        x_g = x_s * amplitude + m_x;
        y_g = y_s * amplitude + m_y;
        z_g = z_s * amplitude + m_z;

        glyph->GetPoints()->SetPoint(i, x_g, y_g, z_g);
    }

    model.SetInput(glyph);
    model.GenerateNormals(true);

    generateModel();
    milxQtRenderWindow::reset();
}
QTGTrackListModel::QTGTrackListModel(QTGSequenceModel* sequenceModel, tg::DataFile* dataFile, QObject *parent)
    : QAbstractListModel(parent)
    , m_sequenceModel(sequenceModel)
    , m_dataFile(dataFile)
{
    m_roles[Track] = "track";
    generateModel();
}
Ejemplo n.º 5
0
void Item::setup(){
  program.build("item");
  program.getUniformLocation("sprites");
  program.getUniformLocation("sprite");
  program.getUniformLocation("position");
  //lastTime = glfwGetTime();

  generateModel();
}
Ejemplo n.º 6
0
Model* LoadModel(char* name)
{
    Model* model = 0;
    Mesh* mesh = LoadOBJ(name);

    if (!mesh)
        return 0;

    DecomposeToTriangles(mesh);

    generateNormals(mesh);

    model = generateModel(mesh);

    return model;
}
Ejemplo n.º 7
0
int Application::main(int argc,char *argv[])
  {
    // Process command line
    BOOM::CommandLine cmd(argc,argv,"");
    if(cmd.numArgs()!=5)
      throw BOOM::String(
"\ntrain-signal-peptide-model <*.gff> <*.fasta> <outfile>\n\
                           <start-codon.model> <field-lengths>\n\
   where <*.gff> contains items with the type \"signal_peptide\"\n\
         <window-len> = length in #codons\n\
         <start-codon.model> is a WMM\n\
         <field-lengths> is a comma-separate list of lengths (in acids)\n\
\n");
    BOOM::String gffFile=cmd.arg(0);
    BOOM::String fastaFile=cmd.arg(1);
    BOOM::String outfile=cmd.arg(2);
    BOOM::String startCodonModelFile=cmd.arg(3);
    BOOM::String lengths=cmd.arg(4);
    initFields(lengths);

    // Load signal peptide coordinates from GFF
    cerr<<"Loading signal peptide coordinates..."<<endl;
    loadSignalPeptideCoords(gffFile,fastaFile);

    // Load transcript coordinates from GFF
    cerr<<"Loading transcript coordinates..."<<endl;
    loadTranscriptCoords(gffFile);    
    
    // Study codon usage in transcripts
    cerr<<"Collecting codon usage statistics from transcripts..."<<endl;
    studyCodonUsage(fastaFile);
    
    // Study amino acid usage in signal peptides
    cerr<<"Collecting amino acid frequencies from signal peptides..."<<endl;
    studyAminoUsage();

    // Generate output
    cerr<<"Finishing model and writing output..."<<endl;
    generateModel(outfile,startCodonModelFile);

    return 0;
  }
void milxQtDiffusionTensorModel::colourByDirection()
{
    vtkSmartPointer<vtkPolyData> currentMesh = model.Result();

    typedef double projectionType;

    ///Determine colours based on axes directions
    vtkSmartPointer<vtkUnsignedCharArray> scalars = vtkSmartPointer<vtkUnsignedCharArray>::New();
        scalars->SetNumberOfComponents(3);
        scalars->SetNumberOfTuples(currentMesh->GetNumberOfPoints());
        scalars->SetName("Fibre Colours");
        scalars->FillComponent(0, 0);
        scalars->FillComponent(1, 0);
        scalars->FillComponent(2, 0);
    vtkSmartPointer<vtkFloatArray> projections = vtkSmartPointer<vtkFloatArray>::New();
        projections->SetNumberOfComponents(3);
        projections->SetNumberOfTuples(currentMesh->GetNumberOfPoints());
        projections->SetName("Fibre Projections");
        projections->FillComponent(0, 0.0);
        projections->FillComponent(1, 0.0);
        projections->FillComponent(2, 0.0);

    emit working(-1);
    if(currentMesh->GetNumberOfLines() == 0)
    {
        printInfo("No lines in model. Computing colours for mesh.");

        ///Use the dot product in each axis
        for(size_t j = 0; j < 3; j ++)
        {
            projectionType axis[3] = {0.0, 0.0, 0.0};
            axis[j] = 1.0;
            cout << "Computing toward axis " << j << endl;

            ///Colour based on each of the gradient values in that direction
            for(vtkIdType k = 0; k < currentMesh->GetNumberOfPoints(); k ++)
            {
                coordinate currentProjection(projections->GetTuple3(k)), position(currentMesh->GetPoint(k));

                projectionType projection = vtkMath::Dot(axis, position.data_block()); //project to axis being done,
                currentProjection[j] = projection; //projection in each direction

                projections->SetTuple3(k, currentProjection[0], currentProjection[1], currentProjection[2]);
            }
        }

        ///Colour based on each of the gradient values in that direction
        for(vtkIdType k = 0; k < currentMesh->GetNumberOfPoints(); k ++)
        {
            coordinate currentProjection(projections->GetTuple3(k));
            coordinate currentProjSquared = element_product(currentProjection, currentProjection);
            projectionType maxProjection = currentProjSquared.max_value();
            currentProjSquared /= maxProjection;

            unsigned char colourOfPoint[3] = {0, 0, 0};
            colourOfPoint[0] = static_cast<unsigned char>( currentProjSquared[0]*255.0 );
            colourOfPoint[1] = static_cast<unsigned char>( currentProjSquared[1]*255.0 );
            colourOfPoint[2] = static_cast<unsigned char>( currentProjSquared[2]*255.0 );

            scalars->SetTupleValue(k, colourOfPoint);
        }

        currentMesh->GetPointData()->SetVectors(projections);
        currentMesh->GetPointData()->SetScalars(scalars);
    }
    else
    {
        printInfo("Re-colouring lines by axes directions");
        //Ensure lines done properly so can colour appropriately
        currentMesh->GetLines()->InitTraversal();
        vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
        vtkSmartPointer<vtkIdList> idList = vtkSmartPointer<vtkIdList>::New();
        std::vector<vtkIdType> trackLengths;
        for(vtkIdType j = 0; j < currentMesh->GetNumberOfLines(); j ++)
        {
            currentMesh->GetLines()->GetNextCell(idList);
            trackLengths.push_back(idList->GetNumberOfIds());
            for(vtkIdType pointId = 0; pointId < idList->GetNumberOfIds(); pointId ++)
            {
    //            std::cout << idList->GetId(pointId) << " ";

                double position[3];
                currentMesh->GetPoint(idList->GetId(pointId), position);
                points->InsertNextPoint(position);
            }
        }

        //Re-stitch lines together
        vtkIdType step = 0;
        vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
        for(size_t j = 0; j < trackLengths.size(); j ++)
        {
            for(vtkIdType k = step; k < trackLengths[j]-1; k ++)
            {
                vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
                    line->GetPointIds()->SetId(0, k);
                    line->GetPointIds()->SetId(1, k+1);
                lines->InsertNextCell(line);
            }
            qDebug() << trackLengths[j] << endl;
            step += trackLengths[j];
        }

        vtkSmartPointer<vtkPolyData> linesPolyData = vtkSmartPointer<vtkPolyData>::New();
            //Add the points to the dataset
            linesPolyData->SetPoints(points);
            //Add the lines to the dataset
            linesPolyData->SetLines(lines);
            linesPolyData->Modified();
        model.SetInput(linesPolyData);
    }

    emit done(-1);
    generateModel();
}
void testBaumwelch(){

  int i, error, tl,z,z1,z2;
  double log_p,first_prob1,first_prob2, first_prob;
  double *proba;
  int *path;
  int* real_path;
  int *path1;
  int* real_path1;
  int *path2;
  int* real_path2;
  model *mo = NULL;
  sequence_t *my_output, *your_output;
  int seqlen = 1000;
  tl = 150;

  mo = malloc(sizeof(model));
  if (mo==NULL) {fprintf(stderr,"Null Pointer in malloc(model).\n");}
  real_path = malloc(seqlen*sizeof(double));
  if(!real_path){ printf("real_path hat kein platz gekriegt\n");}
  real_path1 = malloc(seqlen*sizeof(double));
  if(!real_path1){ printf("real_path hat kein platz gekriegt\n");}
  real_path2 = malloc(seqlen*sizeof(double));
  if(!real_path2){ printf("real_path hat kein platz gekriegt\n");}
  /* generate a model with variable number of states*/
  generateModel(mo, 5);

  /*generate a random sequence*/
  my_output = model_label_generate_sequences(mo, 0, seqlen, 10, seqlen);
  for (i=0; i<seqlen; i++){
    printf("%d", my_output->state_labels[0][i]);
  }
  printf("\n");

  /*viterbi*/
  path = viterbi(mo, my_output->seq[0], my_output->seq_len[0], &first_prob);
  path1 = viterbi(mo, my_output->seq[1], my_output->seq_len[1], &first_prob1);
  path2 = viterbi(mo, my_output->seq[2], my_output->seq_len[2], &first_prob2);
  printf("\n viterbi-path\n");
  z=0;
  z1=0;
  z2=0;
  for (i=0; i<my_output->seq_len[0]; i++){
    if (path1[i] != -1) {
      real_path1[z1]=path1[i];
      z1++;
      printf("%d", path1[i]);
    }
    else printf("hallo");

    if (path2[i] != -1) {
      real_path2[z2]=path2[i];
      z2++;
      printf("%d", path2[i]);
    }
    else printf("hallo");

    if (path[i] != -1) {
      real_path[z]=path[i];
      z++;
      printf("%d", path[i]);
    }

  }
  printf("\n");
  printf("log-prob: %g\n",first_prob);
  my_output->state_labels[0]=real_path;
  my_output->state_labels[1]=real_path1;
  my_output->state_labels[2]=real_path2;

  for (i=0;i<seqlen;i++)
    printf("realpath[%i]=%i",i,real_path[i]);
  proba = malloc(sizeof(double)*tl);

  printf("No of Sequences = %d", my_output->seq_number);

  your_output = model_label_generate_sequences(mo, 0, seqlen, 1, seqlen);
  error = gradient_descent(&mo, your_output, .02, i);
  path = viterbi(mo, my_output->seq[0], my_output->seq_len[0], &log_p);
  free(path);

  /*reestimate_baum_welch_label(mo, my_output);*/
  /*reestimate_baum_welch(mo, my_output);*/

  /*reruns viterbi to check the training*/
  printf("run viterbi second\n");
  path = viterbi(mo, my_output->seq[0], my_output->seq_len[0], &log_p);
  for (i=0; i<(my_output->seq_len[0]*mo->N); i++){
    if (path[i] != -1) {printf("%d", path[i]);}
  }
  printf("\n");
  printf("log-prob: %g\n",log_p);


  /* freeing memory */
  model_free(&mo);
  free(path);
  /*printf("sequence_free success: %d\n", */sequence_free(&my_output)/*)*/;
  free(my_output);

}