Esempio n. 1
0
/*
 * Helper for element and docuemnt constructors to insert sequence
 * of atomic values. Returns true if node was actually inserted.
 * In this case left pointer is changed to the last inserted indirection.
 * In any case at_vals sequence is cleared.
 */
static inline bool
process_atomic_values(xptr& left, const xptr& parent, sequence& at_vals) {
    if (at_vals.size() > 0)
    {
        executor_globals::tmp_op_str_buf.clear();
        tuple_cell tcc;
        sequence::iterator it = at_vals.begin();
        do {
            tcc = tuple_cell::make_sure_light_atomic((*it).cells[0]);
            tcc = cast(tcc, xs_string);
            executor_globals::tmp_op_str_buf.append(tcc);
            it++;
        }
        while (it != at_vals.end());

        at_vals.clear();
        if(executor_globals::tmp_op_str_buf.get_size() > 0) {
            insert_text(indirectionDereferenceCP(left),
                        XNULL,
                        indirectionDereferenceCP(parent),
                        text_source_strbuf(&(executor_globals::tmp_op_str_buf)));
            left = get_last_mo_inderection();
            return true;
        }
    }
    return false;
}
SequenceStatus GestureSeqRecorder::registerSequence(midasMode mode, sequence seq, CommandData seqResponse, std::string name)
{
    sequenceInfo seqInfo;
    seqInfo.seq = seq;
    seqInfo.sequenceResponse = seqResponse;
    seqInfo.sequenceName = name;
    SequenceStatus status = checkLegalRegister(mode, seqInfo);
    if (status != SequenceStatus::SUCCESS)
    {
        return status;
    }

    sequenceList *seqList = (*seqMapPerMode)[mode];
    seqList->push_back(seqInfo);

    seqList = NULL;

    std::vector<int> ids;
    std::vector<PoseLength> lengths;
    sequence::iterator it;

    for (it = seq.begin(); it != seq.end(); ++it)
    {
        ids.push_back(it->type);
        lengths.push_back(it->poseLen);
    }

    std::vector<sequenceImageSet> images = imageManager.formSequenceSetFromIds(ids, lengths);

    gestureSignaller.emitRegisterSequence(seqInfo.id, QString(seqInfo.sequenceName.c_str()), images);

    return SequenceStatus::SUCCESS;
}
  bool
  operator > (const sequence<Iter2, Comp2>& seq) const
  {
    return std::lexicographical_compare (seq.begin(), seq.end(),
					 begin(), end(),
					 compare);
  }
Esempio n. 4
0
viterbi_trellis crf::viterbi_scorer::viterbi(const sequence& seq)
{
    // we only need the scores for the states as the transition scores, set
    // up during construction, will never change between sequences
    scorer_.state_scores(*model_, seq);

    viterbi_trellis table{seq.size(), model_->num_labels()};

    // initialize first column of trellis. We use the original state() and
    // trans() matrices because we are working in the log domain.
    for (label_id lbl{0}; lbl < model_->num_labels(); ++lbl)
        table.probability(0, lbl, scorer_.state(0, lbl));

    // compute remaining columns of trellis using recursive formulation
    for (uint64_t t = 1; t < seq.size(); ++t)
    {
        for (label_id lbl{0}; lbl < model_->num_labels(); ++lbl)
        {
            double max_score = std::numeric_limits<double>::lowest();
            for (label_id in{0}; in < model_->num_labels(); ++in)
            {
                auto score = table.probability(t - 1, in)
                             + scorer_.trans(in, lbl);

                if (score > max_score)
                {
                    max_score = score;
                    table.previous_tag(t, lbl, in);
                }
            }
            table.probability(t, lbl, max_score + scorer_.state(t, lbl));
        }
    }
    return table;
}
Esempio n. 5
0
string decode(const sequence& s)
{
	string result(s.length(), 0);
	for (unsigned int i = 0; i < s.length(); ++i)
		result[i] = s[i] >= 23 ? '.' : kResidues[s[i]];
	return result;
}
Esempio n. 6
0
// is end of a chunk (IOB1)?
int evaluation::is_end_of_chunk_iob1(int human_model, int i, sequence & seq, 
					string b_tag, string i_tag) {
    if (human_model == 1) {
	if (seq[i].label == atoi(b_tag.c_str())) {
	    if (i >= seq.size() - 1) {
		return 1;
	    } else {
		if (seq[i + 1].label != atoi(i_tag.c_str())) {
		    return 1;
		} else {
		    return 0;
		}
	    }
	    
	} else if (seq[i].label == atoi(i_tag.c_str())) {
	    if (i >= seq.size() - 1) {
		return 1;
	    } else {
		if (seq[i + 1].label != atoi(i_tag.c_str())) {
		    return 1;
		} else {
		    return 0;
		}
	    }
	
	} else {
	    return 0;
	}	
    
    } else if (human_model == 2) {
	if (seq[i].model_label == atoi(b_tag.c_str())) {
	    if (i >= seq.size() - 1) {
		return 1;
	    } else {
		if (seq[i + 1].model_label != atoi(i_tag.c_str())) {
		    return 1;
		} else {
		    return 0;
		}
	    }
	    
	} else if (seq[i].model_label == atoi(i_tag.c_str())) {
	    if (i >= seq.size() - 1) {
		return 1;
	    } else {
		if (seq[i + 1].model_label != atoi(i_tag.c_str())) {
		    return 1;
		} else {
		    return 0;
		}
	    }
	
	} else {
	    return 0;
	}	
    
    } else {
	return 0;
    }
}
Esempio n. 7
0
// is end of a chunk (IOB1)?
int is_end_of_chunk_iob1(int human_model, int i, sequence & seq, 
					string b_tag, string i_tag) {
    if (human_model == 1) {
	if (seq[i][seq[i].size() - 2] == b_tag) {
	    if (i >= seq.size() - 1) {
		return 1;
	    } else {
		if (seq[i + 1][seq[i + 1].size() - 2] != i_tag) {
		    return 1;
		} else {
		    return 0;
		}
	    }
	    
	} else if (seq[i][seq[i].size() - 2] == i_tag) {
	    if (i >= seq.size() - 1) {
		return 1;
	    } else {
		if (seq[i + 1][seq[i + 1].size() - 2] != i_tag) {
		    return 1;
		} else {
		    return 0;
		}
	    }
	
	} else {
	    return 0;
	}	
    
    } else if (human_model == 2) {
	if (seq[i][seq[i].size() - 1] == b_tag) {
	    if (i >= seq.size() - 1) {
		return 1;
	    } else {
		if (seq[i + 1][seq[i + 1].size() - 1] != i_tag) {
		    return 1;
		} else {
		    return 0;
		}
	    }
	    
	} else if (seq[i][seq[i].size() - 1] == i_tag) {
	    if (i >= seq.size() - 1) {
		return 1;
	    } else {
		if (seq[i + 1][seq[i + 1].size() - 1] != i_tag) {
		    return 1;
		} else {
		    return 0;
		}
	    }
	
	} else {
	    return 0;
	}	
    
    } else {
	return 0;
    }
}
void show_list(sequence<T> src)
// Pre: (none)
// Post: The items of src are printed to cout (one per line).
{
   for ( src.start(); src.is_item(); src.advance() )
      cout << src.current() << "  ";
}
Esempio n. 9
0
sequence<T> adjoint( sequence<T> X )
{
	int t1 = X.t1();
	int t2 = X.t2();
	for( int t = t1; t <= t2; t++ )
		X(t) = adjoint(X(t));
	return X.timereverse();
}
Esempio n. 10
0
RObject 
AORB::object_key_to_object(sequence<octet>& object_key)
{
  RString str = new String((const char*)object_key.data(), object_key.size(), NormalSST | CCAscii);
  ObjectKey objkey(str);
  if (objkey.isLocal() == true)
    return objkey.getLocalObject();
  // return Skelleton here
  return Nil;
}
Esempio n. 11
0
sequence sequence::breed(sequence const &a, sequence const &b) {
   sequence child;
   for (unsigned int i=0; i < sequence::solution.size(); i++) {
      if (random::probability(0.5)) {
         child.set_gene(i, a.get_gene(i));
      } else {
         child.set_gene(i, b.get_gene(i));
      }
   }
   return child;
}
Esempio n. 12
0
File: w3e4.cpp Progetto: lybeck/NuMe
void generate_vietoris_sequence(sequence& a) {
    if (a.empty())
        return;
    a[0] = rdm(0, MAX_VAL);
    if (a.size() < 2)
        return;
    a[1] = rdm(0, a[0]);
    for (int k = 2; k < a.size(); k++) {
        a[k] = rdm(0, (1.0 * k - 1) / k) * a[k - 1];
    }
}
Esempio n. 13
0
File: w3e4.cpp Progetto: lybeck/NuMe
void generate_vietoris_sequence(sequence& a) {
    if (a.empty())
        return;
    a[0] = 1;
    if (a.size() < 2)
        return;
    a[1] = .5;
    for (int k = 2; k < a.size(); k++) {
        a[k] = a[k - 1] * (k - 1) / k;
    }
}
Esempio n. 14
0
editable_events::editable_events (sequence & seq, int bpm)
 :
    m_events            (),
    m_current_event     (m_events.end()),
    m_sequence          (seq),
    m_midi_parameters
    (
        bpm, seq.get_beats_per_bar(), seq.get_beat_width(), seq.get_ppqn()
    )
{
    // Empty body
}
Esempio n. 15
0
      // compares the given two instances of ss
      double cm_assembly_ssq3::compare(ss const &__first, ss const &__second) const {
        sequence<cchb_dssp> const seq1(__first.get_sequence()), seq2(__second.get_sequence());

        if(seq1.size() != seq2.size()) {
          throw math::compare_error(get_identifier() + ": Sequence length differ, sequence1.length=" +
                                    std::to_string(seq1.size()) + ", sequence2.length=" + std::to_string(seq2.size()));
        } // if

        size_t c_correct(0), h_correct(0), e_correct(0); // initialize
        for(size_t pos(0); pos < seq1.size(); ++pos) { // works for both sequences b/c of same length
          char const sequence1_ss(seq1[pos].get_identifier_char());
          char const sequence2_ss(seq2[pos].get_identifier_char());
          if(sequence1_ss == sequence2_ss) { // actually it's only important that they are the same, not which one
            if(sequence1_ss == 'C') {
              ++c_correct;
            } // if
            else if(sequence1_ss == 'H') {
              ++h_correct;
            } // else if
            else if(sequence1_ss == 'E') {
              ++e_correct;
            } // else if
          } // if
        } // for

        DEBUG << get_identifier() << ": c_correct=" << c_correct << " h_correct=" << h_correct
              << " e_correct=" << e_correct << " seq_len=" << seq1.size();

        return ((double)c_correct + h_correct + e_correct) / seq1.size();
      } // compare()
Esempio n. 16
0
// **************************************************************************
// bool correct(sequence& test, size_t s, size_t cursor_spot, double items[])
//   This function determines if the sequence (test) is "correct" according to
//   these requirements:
//   a. it has exactly s items.
//   b. the items (starting at the front) are equal to
//      items[0] ... items[s-1]
//   c. if cursor_spot < s, then test's cursor must be at
//      the location given by cursor_spot.
//   d. if cursor_spot >= s, then test must not have a cursor.
// NOTE: The function also moves the cursor off the sequence.
// **************************************************************************
bool correct(sequence& test, size_t size, size_t cursor_spot, double items[])
{
    bool has_cursor = (cursor_spot < size); 

    // Check the sequence's size and whether it has a cursor.
    if (!test_basic(test, size, has_cursor))
    {
        cout << "Basic test of size() or is_item() failed." << endl << endl;
        return false;
    }

    // If there is a cursor, check the items from cursor to end of the sequence.
    if (has_cursor && !test_items(test, size, cursor_spot, items))
    {
        cout << "Test of the sequence's items failed." << endl << endl;
        return false;
    }

    // Restart the cursor at the front of the sequence and test items again.
    cout << "I'll call start() and look at the items one more time..." << endl;
    test.start( );
    if (has_cursor && !test_items(test, size, 0, items))
    {
        cout << "Test of the sequence's items failed." << endl << endl;
        return false;
    }

    // If the code reaches here, then all tests have been passed.
    cout << "All tests passed for this sequence." << endl << endl;
    return true;
}
Esempio n. 17
0
// is matching chunk (IOE2)? 
int evaluation::is_matching_chunk_ioe2(int i, sequence & seq, string i_tag, string e_tag) {
    if (!is_start_of_chunk_ioe2(1, i, seq, i_tag, e_tag) || 
	    !is_start_of_chunk_ioe2(2, i, seq, i_tag, e_tag)) {
	return 0;
    }
    
    int len = seq.size();
    int j = i, k = i;
    while (j < len) {
	if (is_end_of_chunk_ioe2(1, j, seq, i_tag, e_tag)) {
	    break;
	} else {
	    j++;
	}
    }

    while (k < len) {
	if (is_end_of_chunk_ioe2(2, k, seq, i_tag, e_tag)) {
	    break;
	} else {
	    k++;
	}
    }

    return (j == k);
}
Esempio n. 18
0
 orthonomial(const sequence &a, const sequence &b, const sequence &c) : n(c.size() - 1), a(a), b(b), c(c) {    
   /* Ze względów bezpieczeństwa. */
   this->a.push_back(0);
   this->b.push_back(0);
   this->c.push_back(0);
   this->c.push_back(0);
 }
Esempio n. 19
0
void crf::tagger::tag(sequence& seq)
{
    auto trellis = scorer_.viterbi(seq);

    auto lbls = util::range(label_id{0},
                            label_id(static_cast<uint32_t>(num_labels_ - 1)));
    auto last_lbl = functional::argmax(
        lbls.begin(), lbls.end(), [&](label_id lbl)
        {
            return trellis.probability(seq.size() - 1, lbl);
        });

    seq[seq.size() - 1].label(*last_lbl);
    for (uint64_t t = seq.size() - 1; t > 0; t--)
        seq[t - 1].label(trellis.previous_tag(t, seq[t].label()));
}
Esempio n. 20
0
double emissionFuncParam::evaluate(sequence& seq , size_t pos) {
    double val = (*emissionFunction)(seq.getUndigitized(),pos);

    if (emissionFuncScaling!=NULL) {
        val = emissionFuncScaling->getWeightedScore(val);
    }

    return val;
}
Esempio n. 21
0
void perceptron::tag(sequence& seq) const
{
    for (uint64_t t = 0; t < seq.size(); ++t)
    {
        analyzer_.analyze(seq, t);
        seq[t].label(model_.best_class(seq[t].features()));
        seq[t].tag(analyzer_.tag(seq[t].label()));
    }
}
Esempio n. 22
0
sequence::sequence(const sequence& seq){
  capacity=seq.capacity;
  used=seq.used;
  data=new int[capacity];
  seq.shift(data);
  missing=new int[capacity];
  for (size_t i = 0; i < capacity; i++)
    missing[i]=0;
  numMissing=0;
}
Esempio n. 23
0
// **************************************************************************
// bool test_basic(const sequence& test, size_t s, bool has_cursor)
//   Postcondition: A return value of true indicates:
//     a. test.size() is s, and
//     b. test.is_item() is has_cursor.
//   Otherwise the return value is false.
//   In either case, a description of the test result is printed to cout.
// **************************************************************************
bool test_basic(const sequence& test, size_t s, bool has_cursor)
{
    bool answer;

    cout << "Testing that size() returns " << s << " ... ";
    cout.flush( );
    answer = (test.size( ) == s);
    cout << (answer ? "Passed." : "Failed.") << endl;
    
    if (answer)
    {
        cout << "Testing that is_item() returns ";
        cout << (has_cursor ? "true" : "false") << " ... ";
        cout.flush( );
        answer = (test.is_item( ) == has_cursor);
        cout << (answer ? "Passed." : "Failed.") << endl;
    }

    return answer;
}
Esempio n. 24
0
bool sequence::operator==(const sequence& seq){
  if(capacity!=seq.capacity) return false;
  if(used!=seq.used) return false;
  int* temp1=new int[capacity];
  shift(temp1);
  int* temp2=new int[capacity];
  seq.shift(temp2);
  for (size_t i = 0; i < used; i++) {
    if(temp1[i]!=temp2[i]) return false;
  }
  return true;
}
Esempio n. 25
0
// **************************************************************************
// bool test_items(sequence& test, size_t s, size_t i, double items[])
//   The function determines if the test sequence has the correct items
//   Precondition: The size of the items array is at least s.
//   Postcondition: A return value of true indicates that test.current()
//   is equal to items[i], and after test.advance() the result of
//   test.current() is items[i+1], and so on through items[s-1].
//   At this point, one more advance takes the cursor off the sequence.
//   If any of this fails, the return value is false.
//   NOTE: The test sequence has been changed by advancing its cursor.
// **************************************************************************
bool test_items(sequence& test, size_t s, size_t i, double items[])
{
    bool answer = true;
    
    cout << "The cursor should be at item [" << i << "]" << " of the sequence\n";
    cout << "(counting the first item as [0]). I will advance the cursor\n";
    cout << "to the end of the sequence, checking that each item is correct...";
    cout.flush( );
    while ((i < s) && test.is_item( ) && (test.current( ) == items[i]))
    {
        i++;
        test.advance( );
    }

    if ((i != s) && !test.is_item( ))
    {   // The test.is_item( ) function returns false too soon.
        cout << "\n    Cursor fell off the sequence too soon." << endl;
        answer = false;
    }
    else if (i != s)
    {   // The test.current( ) function returned a wrong value.
        cout << "\n    The item [" << i << "] should be " << items[i] << ",\n";
        cout << "    but it was " << test.current( ) << " instead.\n";
        answer = false;
    }
    else if (test.is_item( ))
    {   // The test.is_item( ) function returns true after moving off the sequence.
        cout << "\n    The cursor was moved off the sequence,";
        cout << " but is_item still returns true." << endl;
        answer = false;
    }

    cout << (answer ? "Passed." : "Failed.") << endl;
    return answer;
}
Esempio n. 26
0
// counting matching chunks (IOE2)
int count_matching_chunks_ioe2(sequence & seq, string i_tag, string e_tag) {
    int count = 0;

    for (int i = 0; i < seq.size(); i++) {
	if (is_start_of_chunk_ioe2(1, i, seq, i_tag, e_tag)) {
	    if (is_matching_chunk_ioe2(i, seq, i_tag, e_tag)) {
		count++;
	    }
	}
    }

    return count;
}
Esempio n. 27
0
sequence<R> operator*( const sequence<T1> &X, const sequence<T2> &Y )
{
	if( X.size()==0 || Y.size()==0 )
		return sequence<R>();
	vec<R> vec = conv( X.buffer(), Y.buffer() );
	int t1     = X.t1() + Y.t1();
	return sequence<R>( vec, t1 );
}
Esempio n. 28
0
// counting number of chunks (IOE2)
int count_chunks_ioe2(int human_model, sequence & seq, string i_tag, string e_tag) {
    int count = 0;

    for (int i = 0; i < seq.size(); i++) {
	if (human_model == 1 && is_start_of_chunk_ioe2(1, i, seq, i_tag, e_tag)) {
	    count++;
	}
	
	if (human_model == 2 && is_start_of_chunk_ioe2(2, i, seq, i_tag, e_tag)) {
	    count++;
	}
    }

    return count;
}
Esempio n. 29
0
void convert_IOB2_IOB1(int is_cap, int is_last, sequence & seq) {
    map<int, int> fixedlabels;
    map<int, int>::iterator obsrit;

    char begin = is_cap ? 'B' : 'b';
    char inside = is_cap ? 'I' : 'i';
    string INSIDE = is_cap ? "I" : "i";

    string str1, str2, istr, newlabel;
    int i, len = seq.size();        

    for (i = 1; i < len; i++) {
	int col1 = is_last ? seq[i - 1].size() - 1 : seq[i - 1].size() - 2;
	int col2 = is_last ? seq[i].size() - 1 : seq[i].size() - 2;
	
	str1 = seq[i - 1][col1];
	str2 = seq[i][col2];
	
	if (str2[0] != begin) {
	    continue;
	}
	
	istr = INSIDE;
	istr += strtail(str2);
	
	if (str1 == str2 || str1 == istr) {
	    fixedlabels.insert(pair<int, int>(i, i));
	}
    }
    
    for (i = 0; i < len; i++) {
	obsrit = fixedlabels.find(i);
	if (obsrit != fixedlabels.end()) {
	    continue;
	}
	
	int col = is_last ? seq[i].size() - 1 : seq[i].size() - 2;
	if (seq[i][col][0] == begin) {
	    // B- or b- => I- or i-
	    newlabel = INSIDE;
	    newlabel += strtail(seq[i][col]);
	    seq[i][col] = newlabel;
	}		
    }
}
Esempio n. 30
0
sequence<T> inv(const sequence<T>& X, int t1, int t2)
{
    int		YL = t2-t1+1;

    // Convolution matrix
    mat<T>	CX = convmat(X,YL);

    // Impulse function
    int		DL = CX.rows();
    vec<T>	D = zeros(DL);
    int 	i = -t1-X.t1();
    if(i > 0 && i < DL)
        D(i) = 1;

    // Inverse sequence
    vec<T>	Y = backslash( CX, D );
    return sequence<T>( Y, t1 );
}