Skip to content

Commit

Permalink
Add support for continuous features or observations to the HMSVM
Browse files Browse the repository at this point in the history
- Major changes in HMSVMModel
- Add convenience init_training method in StructuredModel
- TwoStateModel::simulate_two_state_data -> simulate_data with arguments
- Fix bug with default value of m_use_director_risk in StructuredModel cto.
  • Loading branch information
iglesias committed Jun 3, 2013
1 parent 05cbbc7 commit 8496e3f
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 60 deletions.
17 changes: 16 additions & 1 deletion src/shogun/lib/SGVector.cpp
Expand Up @@ -994,7 +994,7 @@ template<class T> void SGVector<T>::save(CFile* saver)
saver->set_vector(vector, vlen);
SG_RESET_LOCALE;
}

#define MATHOP(op) \
template <class T> void SGVector<T>::op() \
{ \
Expand Down Expand Up @@ -1030,6 +1030,21 @@ template <class T> void SGVector<T>::pow(T q)
vector[i]=(T) CMath::pow((double) vector[i], (double) q);
}

template <class T>
SGVector<float64_t> SGVector<T>::linspace_vec(T start, T end, int32_t n)
{
return SGVector<float64_t>(linspace(start, end, n), n);
}

template <class T>
float64_t* SGVector<T>::linspace(T start, T end, int32_t n)
{
float64_t* output = SG_MALLOC(float64_t, n);
CMath::linspace(output, start, end, n);

return output;
}

template class SGVector<bool>;
template class SGVector<char>;
template class SGVector<int8_t>;
Expand Down
18 changes: 18 additions & 0 deletions src/shogun/lib/SGVector.h
Expand Up @@ -88,6 +88,24 @@ template<class T> class SGVector : public SGReferencedData
*/
static T* randperm(int32_t n);

/** Returns a vector with n linearly spaced elements between start and end.
*
* @param start beginning of the interval to divide
* @param end upper bound of the interval to divide
* @param n number of elements used to divide the interval
* @return vector with linearly spaced elements within the interval
*/
static SGVector<float64_t> linspace_vec(T start, T end, int32_t n);

/** Returns an array with n linearly spaced elements between start and end.
*
* @param start beginning of the interval to divide
* @param end upper bound of the interval to divide
* @param n number of elements used to divide the interval
* @return array with linearly spaced elements within the interval
*/
static float64_t* linspace(T start, T end, int32_t n);

/** For a sorted (ascending) vector, gets the index after the first
* element that is smaller than the given one
*
Expand Down
13 changes: 13 additions & 0 deletions src/shogun/mathematics/Math.cpp
Expand Up @@ -183,3 +183,16 @@ float64_t CMath::Align(
// return the final cost
return actCost;
}

void CMath::linspace(float64_t* output, float64_t start, float64_t end, int32_t n)
{
float64_t delta = (end-start) / (n-1);
float64_t v = start;
index_t i = 0;
while ( v <= end )
{
output[i++] = v;
v += delta;
}
output[n-1] = end;
}
9 changes: 9 additions & 0 deletions src/shogun/mathematics/Math.h
Expand Up @@ -577,6 +577,15 @@ class CMath : public CSGObject
return res/factorial(k);
}

/** Builds an array with n linearly spaced elements between start and end.
*
* @param output array with linearly spaced elements within the interval
* @param start beginning of the interval to divide
* @param end upper bound of the interval to divide
* @param n number of elements used to divide the interval
*/
static void linspace(float64_t* output, float64_t start, float64_t end, int32_t n = 100);

/** performs a bubblesort on a given matrix a.
* it is sorted in ascending order from top to bottom
* and left to right */
Expand Down
2 changes: 2 additions & 0 deletions src/shogun/structure/DualLibQPBMSOSVM.cpp
Expand Up @@ -88,6 +88,8 @@ bool CDualLibQPBMSOSVM::train_machine(CFeatures* data)
if (data)
set_features(data);

// Initialize the model for training
m_model->init_training();
// call the solver
switch(m_solver)
{
Expand Down

0 comments on commit 8496e3f

Please sign in to comment.