/** * @brief likelyhood : method to compute the log * likeyhood of observed sequence * @param sequence :input observation sequence * @return */ float ocv::CHMM::predictIterative(Mat sequence,bool init) { //computing the probability of observed sequence //using forward algorithm if(init==true) { count=0; prob=0; _alpha=MatrixXd(_nstates,_maxseqlen); _scale=MatrixXd(1,_maxseqlen); } int i=count; forwardMatrixIterative(sequence,init,i); prob=(_scale(0,i)); //prob=-prob; //cerr << prob <<":" << count <<"--"; count=count+1; return prob; }
//computing p(xn.....xN,zn) void ocv::DHMM::backwardMatrix(vector<int> &sequence) { _beta=MatrixXf(_nstates,sequence.size()+1); int len=sequence.size()+1; for(int i=len-1;i>=0;i--) { for(int j=0;j<_nstates;j++) { if(i==len-1) { _beta(j,i)=1; } else { float s=0; for(int k=0;k<_nstates;k++) s=s+_beta(k,i+1)*_emission(k,sequence[i])*_transition(j,k); _beta(j,i)=s*_scale(0,i+1); } } } }
/** * @brief forwardMatrix : method computes probability //compute p(x1 ... xn,zn) * using the forward algorithm * @param sequence : is input observation sequence */ void ocv::CHMM::forwardMatrix(Mat &sequence) { int len=sequence.rows; int dim=sequence.cols; _seqlen=len-1; for(int i=0;i<len;i++) { for(int j=0;j<_nstates;j++) { if(i==0) { _alpha(j,i)=_emission[j].Prob(sequence.row(i))*_initial(0,j); } else { float s=0; for(int k=0;k<_nstates;k++) s=s+_transition(k,j)*_alpha(k,i-1); //changed from sequence.row(i-1) to sequence.row(i) //need to verifyt the forward algorithm _alpha(j,i)=_emission[j].Prob(sequence.row(i))*s; } } float scale=0; for(int j=0;j<_nstates;j++) { scale=scale+_alpha(j,i); } //scale=scale+std::numeric_limits<float>::epsilon(); if(scale==0) scale=std::numeric_limits<float>::epsilon(); scale=1.f/(scale); //commented the below code need to verify //if(i==0) // _scale(0,i)=1; // else _scale(0,i)=scale; for(int j=0;j<_nstates;j++) { _alpha(j,i)=scale*_alpha(j,i); } } }
/** * vsg_matrix3@t@_scale_new: * @x: a #@type@ * @y: a #@type@ * * Creates a new #VsgMatrix3@t@ corresponding to a 2D scaling with * coordinates (@x,@y). * * Returns: new #VsgMatrix3@t@ instance */ VsgMatrix3@t@ *vsg_matrix3@t@_scale_new (@type@ x, @type@ y) { VsgMatrix3@t@ *result = vsg_matrix3@t@_identity_new (); vsg_matrix3@t@_scale (result, x, y); return result; }
/** * @brief forwardMatrix : method computes probability //compute p(x1 ... xn,zn) * using the forward algorithm * @param sequence : is input observation sequence */ void ocv::DHMM::forwardMatrix(vector<int> &sequence) { int len=sequence.size()+1; _seqlen=len-1; _alpha=MatrixXf(_nstates,_seqlen+1); _scale=MatrixXf(1,_seqlen+1); for(int i=0;i<len;i++) { for(int j=0;j<_nstates;j++) { if(i==0) _alpha(j,i)=_emission(j,sequence[i])*_initial(0,j); else { float s=0; for(int k=0;k<_nstates;k++) s=s+_transition(k,j)*_alpha(k,i-1); _alpha(j,i)=_emission(j,sequence[i-1])*s; } } float scale=0; for(int j=0;j<_nstates;j++) { scale=scale+_alpha(j,i); } scale=1.f/scale; if(i==0) _scale(0,i)=1; else _scale(0,i)=scale; for(int j=0;j<_nstates;j++) { _alpha(j,i)=scale*_alpha(j,i); } } }
MemoryUnitPtr _scale( const uint8_t* ptr, const size_t size ) { const ssize_t nElems = size / sizeof( O ); auto memory = MemoryUnitPtr( new AllocMemoryUnit( size )); const I* in = reinterpret_cast< const I* >( ptr ); O* out = memory->getData< O >(); _scale( in, out, nElems ); return memory; }
void xSceneSelection::setRotGizmo() { if(m_pRotGizimo == NULL) { m_pRotGizimo = dynamic_cast<xSceneHelperDrawableNode*>(XEvol_CreateSceneNode(L"xSceneHelperDrawableNode" , m_pEvolEnv->scene() , NULL) ); m_pRotGizimo->attachDrawElement(m_ArcBall); xvec3 _scale(30.0f, 30.0f , 30.f); m_pRotGizimo->placement()->setScale( _scale ); m_pRotGizimo->setInScene(false); } setGizmoNode(m_pRotGizimo); }
int set_menu_sub(MENU *m, WINDOW *sub) { if (m) { if (Posted(m)) { return (E_POSTED); } UserSub(m) = sub; /* Since window size has changed go recalculate sizes */ _scale(m); } else { UserSub(Dfl_Menu) = sub; } return (E_OK); }
int set_menu_format(MENU *m, int rows, int cols) { if (rows < 0 || cols < 0) { return (E_BAD_ARGUMENT); } if (m) { if (Posted(m)) { return (E_POSTED); } if (rows == 0) { rows = FRows(m); } if (cols == 0) { cols = FCols(m); } /* The pattern buffer is allocated after items have been */ /* connected */ if (Pattern(m)) { IthPattern(m, 0) = '\0'; Pindex(m) = 0; } FRows(m) = rows; FCols(m) = cols; Cols(m) = min(cols, Nitems(m)); Rows(m) = (Nitems(m)-1) / cols + 1; Height(m) = min(rows, Rows(m)); Top(m) = 0; Current(m) = IthItem(m, 0); SetLink(m); _scale(m); } else { if (rows > 0) { FRows(Dfl_Menu) = rows; } if (cols > 0) { FCols(Dfl_Menu) = cols; } } return (E_OK); }
/** * @brief likelyhood : method to compute the log * likeyhood of observed sequence * @param sequence :input observation sequence * @return */ float ocv::CHMM::likelyhood(Mat sequence) { float prob=0; //computing the probability of observed sequence //using forward algorithm forwardMatrix(sequence); //computing the log probability of observed sequence for(int i=0;i<sequence.rows;i++) { //for(int j=0;j<_nstates;j++) { prob=prob+std::log(_scale(0,i)); } } return -prob; }
int set_menu_opts(MENU *m, int opt) { ITEM **ip; if (m) { if (Posted(m)) { return (E_POSTED); } /* Check to see if the ROWMAJOR option is changing. If so, */ /* set top and current to 0. */ if ((opt & O_ROWMAJOR) != RowMajor(m)) { Top(m) = 0; Current(m) = IthItem(m, 0); (void) set_menu_format(m, FRows(m), FCols(m)); } /* if O_NONCYCLIC option changed, set bit to re-link items */ if ((opt & O_NONCYCLIC) != (Mopt(m) & O_NONCYCLIC)) { SetLink(m); } Mopt(m) = opt; if (OneValue(m) && Items(m)) { for (ip = Items(m); *ip; ip++) { /* Unset values if selection not allowed. */ Value(*ip) = FALSE; } } _scale(m); /* Redo sizing information */ } else { Mopt(Dfl_Menu) = opt; } return (E_OK); }
Point Window::scale(void) { Point _scale(windowMax.x() - windowMin.x(), windowMax.y() - windowMin.y()); return _scale; }
const Ogre::Vector3 AtmosphereManager::getColorAt(const Ogre::Vector3& Direction) const { if (Direction.y<0) { return Ogre::Vector3(0,0,0); } // Parameters double Scale = 1.0f / (mOptions.OuterRadius - mOptions.InnerRadius), ScaleDepth = (mOptions.OuterRadius - mOptions.InnerRadius) / 2.0f, ScaleOverScaleDepth = Scale / ScaleDepth, Kr4PI = mOptions.RayleighMultiplier * 4.0f * Ogre::Math::PI, KrESun = mOptions.RayleighMultiplier * mOptions.SunIntensity, Km4PI = mOptions.MieMultiplier * 4.0f * Ogre::Math::PI, KmESun = mOptions.MieMultiplier * mOptions.SunIntensity; // --- Start vertex program simulation --- Ogre::Vector3 uLightDir = -getSunDirection(), v3Pos = Direction, uCameraPos = Ogre::Vector3(0, mOptions.InnerRadius + (mOptions.OuterRadius-mOptions.InnerRadius)*mOptions.HeightPosition, 0), uInvWaveLength = Ogre::Vector3( 1.0f / Ogre::Math::Pow(mOptions.WaveLength.x, 4.0f), 1.0f / Ogre::Math::Pow(mOptions.WaveLength.y, 4.0f), 1.0f / Ogre::Math::Pow(mOptions.WaveLength.z, 4.0f)); // Get the ray from the camera to the vertex, and it's length (far point) v3Pos.y += mOptions.InnerRadius; Ogre::Vector3 v3Ray = v3Pos - uCameraPos; double fFar = v3Ray.length(); v3Ray /= fFar; // Calculate the ray's starting position, then calculate its scattering offset Ogre::Vector3 v3Start = uCameraPos; double fHeight = uCameraPos.y, fStartAngle = v3Ray.dotProduct(v3Start) / fHeight, fDepth = Ogre::Math::Exp(ScaleOverScaleDepth * (mOptions.InnerRadius - uCameraPos.y)), fStartOffset = fDepth * _scale(fStartAngle, ScaleDepth); // Init loop variables double fSampleLength = fFar /(double)mOptions.NumberOfSamples, fScaledLength = fSampleLength * Scale, fHeight_, fDepth_, fLightAngle, fCameraAngle, fScatter; Ogre::Vector3 v3SampleRay = v3Ray * fSampleLength, v3SamplePoint = v3Start + v3SampleRay * 0.5f, color, v3Attenuate; // Loop the ray for (int i = 0; i < mOptions.NumberOfSamples; i++) { fHeight_ = v3SamplePoint.length(); fDepth_ = Ogre::Math::Exp(ScaleOverScaleDepth * (mOptions.InnerRadius-fHeight_)); fLightAngle = uLightDir.dotProduct(v3SamplePoint) / fHeight_; fCameraAngle = v3Ray.dotProduct(v3SamplePoint) / fHeight_; fScatter = (fStartOffset + fDepth*(_scale(fLightAngle, ScaleDepth) - _scale(fCameraAngle, ScaleDepth))); v3Attenuate = Ogre::Vector3( Ogre::Math::Exp(-fScatter * (uInvWaveLength.x * Kr4PI + Km4PI)), Ogre::Math::Exp(-fScatter * (uInvWaveLength.y * Kr4PI + Km4PI)), Ogre::Math::Exp(-fScatter * (uInvWaveLength.z * Kr4PI + Km4PI))); // Accumulate color v3Attenuate *= (fDepth_ * fScaledLength); color += v3Attenuate; // Next sample point v3SamplePoint += v3SampleRay; } // Outputs Ogre::Vector3 oRayleighColor = color * (uInvWaveLength * KrESun), oMieColor = color * KmESun, oDirection = uCameraPos - v3Pos; // --- End vertex program simulation --- // --- Start fragment program simulation --- double cos = uLightDir.dotProduct(oDirection) / oDirection.length(), cos2 = cos*cos, rayleighPhase = 0.75 * (1.0 + 0.5*cos2), g2 = mOptions.G*mOptions.G, miePhase = 1.5f * ((1.0f - g2) / (2.0f + g2)) * (1.0f + cos2) / Ogre::Math::Pow(1.0f + g2 - 2.0f * mOptions.G * cos, 1.5f); Ogre::Vector3 oColor; if (mSkyX->getLightingMode() == SkyX::LM_LDR) { oColor = Ogre::Vector3( 1 - Ogre::Math::Exp(-mOptions.Exposure * (rayleighPhase * oRayleighColor.x + miePhase * oMieColor.x)), 1 - Ogre::Math::Exp(-mOptions.Exposure * (rayleighPhase * oRayleighColor.y + miePhase * oMieColor.y)), 1 - Ogre::Math::Exp(-mOptions.Exposure * (rayleighPhase * oRayleighColor.z + miePhase * oMieColor.z))); } else { oColor = rayleighPhase * oRayleighColor + miePhase * oMieColor; } // For night rendering oColor += Ogre::Math::Clamp<Ogre::Real>(((1 - std::max(oColor.x, std::max(oColor.y, oColor.z))*10)), 0, 1) * (Ogre::Vector3(0.05, 0.05, 0.1) * (2-0.75f*Ogre::Math::Clamp<Ogre::Real>(-uLightDir.y, 0, 1)) * Ogre::Math::Pow(1-Direction.y, 3)); // --- End fragment program simulation --- // Output color return oColor; }
/**= * @brief forwardMatrix : method computes probability //compute p(x1 ... xn,zn) * using the forward algorithm * @param sequence : is input observation sequence */ void ocv::CHMM::forwardMatrixIterative(Mat &sequence,bool init,int i) { int dim=sequence.cols; for(int j=0;j<_nstates;j++) { if(init==true||i==0) { _alpha(j,0)=_emission[j].Prob(sequence)+(_initial(0,j)); } else { float s=0; vector<float> work; for(int k=0;k<_nstates;k++) work.push_back((_transition(k,j))+_alpha(k,i-1)); \ float r=EigenUtils::logsumexp(work); //changed from sequence.row(i-1) to sequence.row(i) //need to verifyt the forward algorithm _alpha(j,i)=_emission[j].Prob(sequence)+r; } //cerr << _emission[j].Prob(sequence) << endl; } float scale=0; vector<float> alpha; for(int j=0;j<_nstates;j++) { if(_alpha(j,i)<=-1e200) _alpha(j,i)=-1*std::numeric_limits<float>::infinity(); alpha.push_back(_alpha(j,i)); } scale=EigenUtils::logsumexp(alpha); //cerr << scale << ":" ; //if(scale==0) // scale=std::numeric_limits<float>::epsilon(); //scale=1.f/(scale); //commented the below code need to verify //if(i==0) // _scale(0,i)=1; // else _scale(0,i)=scale; /*for(int j=0;j<_nstates;j++) { _alpha(j,i)=scale*_alpha(j,i); }*/ }
static svg_status_t _SDL_SVG_ApplyViewBox (void *closure, svg_view_box_t view_box, svg_length_t *width, svg_length_t *height) { SDL_svg_context *c = closure; double vpar, svgar; double logic_width, logic_height; double logic_x, logic_y; double phys_width, phys_height; dprintf("svg_ApplyViewBox\n"); phys_width = ConvertLength(width); phys_height = ConvertLength(height); vpar = view_box.box.width / view_box.box.height; svgar = phys_width / phys_height; logic_x = view_box.box.x; logic_y = view_box.box.y; logic_width = view_box.box.width; logic_height = view_box.box.height; if (view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_NONE) { _scale (c, phys_width / logic_width, phys_height / logic_height); _translate (c, -logic_x, -logic_y); } else if((vpar < svgar && view_box.meet_or_slice == SVG_MEET_OR_SLICE_MEET) || (vpar >= svgar && view_box.meet_or_slice == SVG_MEET_OR_SLICE_SLICE)) { _scale (c, phys_height / logic_height, phys_height / logic_height); if (view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMINYMIN || view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMINYMID || view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMINYMAX) _translate (c, -logic_x, -logic_y); else if(view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMIDYMIN || view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMIDYMID || view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMIDYMAX) _translate (c, -logic_x - (logic_width - phys_width * logic_height / phys_height) / 2, -logic_y); else _translate (c, -logic_x - (logic_width - phys_width * logic_height / phys_height), -logic_y); } else { _scale (c, phys_width / logic_width, phys_width / logic_width); if (view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMINYMIN || view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMIDYMIN || view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMAXYMIN) _translate (c, -logic_x, -logic_y); else if(view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMINYMID || view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMIDYMID || view_box.aspect_ratio == SVG_PRESERVE_ASPECT_RATIO_XMAXYMID) _translate (c, -logic_x, -logic_y - (logic_height - phys_height * logic_width / phys_width) / 2); else _translate (c, -logic_x, -logic_y - (logic_height - phys_height * logic_width / phys_width)); } return SVG_STATUS_SUCCESS; }