コード例 #1
0
ファイル: lch_plugin.c プロジェクト: tiagojc/IBTSFIF
double Distance(char *fv1_path, char *fv2_path)
{
  Histogram *lch1=NULL;
  Histogram *lch2=NULL;
  double distance;

  lch1 = ReadFileHistogram(fv1_path);
  lch2 = ReadFileHistogram(fv2_path);

  distance= (double) L1Distance(lch1, lch2);

  DestroyHistogram(&lch1);
  DestroyHistogram(&lch2);

  return distance;
}
コード例 #2
0
ファイル: bic_plugin.c プロジェクト: tiagojc/IBTSFIF
double Distance(char *fv1_path, char *fv2_path)
{
  Histogram *bic1=NULL;
  Histogram *bic2=NULL;
  double distance;

  bic1 = ReadFileHistogram(fv1_path);
  bic2 = ReadFileHistogram(fv2_path);

  distance = (double) L1Distance(bic1, bic2);

  DestroyHistogram(&bic1);
  DestroyHistogram(&bic2);

  return distance;
}
コード例 #3
0
ファイル: acc_plugin.c プロジェクト: rafaelalmeida/poc
double Distance(void *fv1, void *fv2)
{
  Histogram *acc1=NULL;
  Histogram *acc2=NULL;
  double distance;

  acc1 = (Histogram*) fv1;
  acc2 = (Histogram*) fv2;

  distance = (double) L1Distance(acc1, acc2);

  //DestroyHistogram(&acc1);
  //DestroyHistogram(&acc2);

  return distance;
}
コード例 #4
0
ファイル: acc_distance.c プロジェクト: tiagojc/IBTSFIF
int main(int argc, char** argv)
{
  Histogram *acc1=NULL;
  Histogram *acc2=NULL;
  ulong distance;

  if (argc != 3) {
    fprintf(stderr,"usage: acc_distance <fv1_path> <fv2_path>\n");
    exit(-1);
  }

  acc1 = ReadFileHistogram(argv[1]);
  acc2 = ReadFileHistogram(argv[2]);

  distance=L1Distance(acc1, acc2);
  printf("%ld\n",distance);

  DestroyHistogram(&acc1);
  DestroyHistogram(&acc2);

  return(0);
}
コード例 #5
0
ファイル: ccv_distance.c プロジェクト: tiagojc/IBTSFIF
int main(int argc, char** argv)
{
  Histogram *ccv1=NULL;
  Histogram *ccv2=NULL;
  double distance;

  if (argc != 3) {
    fprintf(stderr,"usage: ccv_distance fv1_path fv2_path\n");
    exit(-1);
  }

  ccv1 = ReadFileHistogram(argv[1]);
  ccv2 = ReadFileHistogram(argv[2]);

  distance=(double)L1Distance(ccv1, ccv2);
  printf("%lf\n",distance);

  DestroyHistogram(&ccv1);
  DestroyHistogram(&ccv2);

  return(0);
}
コード例 #6
0
ファイル: PreProcessData.cpp プロジェクト: mrevow/tools-ann
// Pair net. The full input is two training samples and 
// the target is set to 1 if the two examples have the same category
// else the target is 0. The second input is randomly chosen in a two setp process:
// 1) Choose  a selection radius with probability probSame if the second example will be "same"
//		or "different"
// 2) The second example is then chosen randomly from teh entire training set using the "radius"
//	selected in step (1)
HRESULT PreProcPairInputImages(PVOID pThis,
                     const  PRE_PROCESS_DATA_ARGS *pArgs,
                     LPCTSTR lpFile
                     )
{
	static float	s_probSame = 0.5;
	static int		s_sameRadius = 3;		// Note same radius is an absolute value
	static float	s_diffRadius = 1.0F;	// While Diff radius is expresed as fraction of the data set size
	static bool		s_bInputResized = false;
	static bool		s_bUseAutoEncoder = false;
	static bool		s_bDoSampleSphere = false;
	static int		s_cExtraTargetLayer = 0;
	static int		s_cExtraInput = 0;
	static int		s_cMaxRetry = 5;
	static int		s_cTupleSize = 1;
	static TCHAR	s_pairFile[MAX_PATH];
	static CDataTuple *pDataTuple = NULL;

	HRESULT hRet = S_OK;

    if (NULL != lpFile)
    {
        FILE    *fp;
        fp = _tfopen(lpFile, TEXT("r"));
        if (NULL != fp)
        {
            TCHAR   awCmd[MAX_PATH];
            TCHAR   awVal[MAX_PATH];
            float   val;
			s_pairFile[0] = TEXT('\0');
			s_bUseAutoEncoder = false;
			s_cExtraTargetLayer = 0;

			if (NULL != pDataTuple)
			{
				delete pDataTuple;
				pDataTuple = NULL;
			}

            while (2 == _ftscanf(fp, TEXT("%s %s"), awCmd, awVal))
            {
				val = (float)_tstof(awVal);
                if (0 == _tcsicmp(awCmd, TEXT("probsame")))
                {
                    s_probSame = val;
                }
                else if (0 ==  _tcsicmp(awCmd, TEXT("sameradius")))
                {
                    s_sameRadius = (int)val;
                }
                else if (0 == _tcsicmp(awCmd, TEXT("diffradius")))
                {
                    s_diffRadius = val;
                }
                else if (0 == _tcsicmp(awCmd, TEXT("maxretry")))
                {
                    s_cMaxRetry = (int)val;
                }
				else if (0 == _tcsicmp(awCmd, TEXT("pairfile")))
                {
					_tcscpy_s(s_pairFile, ARRAYSIZE(s_pairFile), awVal);
                }
                else if (0 == _tcsicmp(awCmd, TEXT("tuplesize")))
                {
                    s_cTupleSize = (int)val;
                }
                else if (0 == _tcsicmp(awCmd, TEXT("extrainput")))
                {
                    s_cExtraInput = (int)val;
                }
				else if (0 == _tcsicmp(awCmd, TEXT("autoencoder")))
                {
					s_bUseAutoEncoder = true;
                }
				else if (0 == _tcsicmp(awCmd, TEXT("numextratarget")))
                {
					s_cExtraTargetLayer = (int)val;
                }
				else if (0 == _tcsicmp(awCmd, TEXT("dosamplesphere")))
                {
					s_bDoSampleSphere = (val == 0.0F) ? false : true;
                }

            }
            fclose(fp);

            // Did everyting load
            if (    s_probSame >= 0.0F
                && s_probSame <= 1.0F 
                && s_sameRadius > 0
                && s_diffRadius > 0
                && s_diffRadius <= 1.0F
                )
            {
                hRet = S_OK;
				s_bInputResized = false;
            }
            return hRet;
        }
        return E_INVALIDARG;
    }

    NNData    *pData = (NNData *)pThis;
	PRE_PROCESS_DATA_ARGS *pIO = (PRE_PROCESS_DATA_ARGS*)pArgs;

	if (NULL == pThis || NULL == pArgs)
    {
        hRet =  E_INVALIDARG;
    }

	if (SUCCEEDED(hRet) && false == s_bInputResized)
	{
		// First time around increase the size of the buffers holding inputs and its stats
		hRet = ResizeAllInputBuffers(pData, pIO, s_cExtraInput, s_cExtraTargetLayer, s_cTupleSize);

		if (SUCCEEDED(hRet))
		{
			s_bInputResized = true;
		}
		else
		{
			return hRet;
		}
	}

	if (SUCCEEDED(hRet))
	{
		if (NULL == pDataTuple && _tcslen(s_pairFile) > 0)
		{
			pDataTuple = new CDataTuple(pData->GetNumRows(), s_cTupleSize);
			if (!SUCCEEDED(pDataTuple->LoadFromFile(s_pairFile)))
			{
				delete pDataTuple;
				pDataTuple= NULL;
			}
		}

		int		iRadius;
		int iOtherSamp = 0, iOtherSamp2 = 0;
		DREAL *pThisTarget = *(pData->GetTargetExamples() + pData->GetCurRow());
		int cRetry = 0;
		int cOtherSamp = 1;

		if (NULL == pDataTuple)
		{
			DREAL *pOtherTarget;
			if (frand() <= s_probSame)
			{
				iRadius = s_sameRadius;
				do 
				{
					iOtherSamp = PickOtherSamp(pData, iRadius);
					pOtherTarget = *(pData->GetTargetExamples() + iOtherSamp);
					++cRetry;
				} while (*pOtherTarget != *pIO->m_pTarget && cRetry < s_cMaxRetry);
			}
			else
			{
				iRadius = (int)(s_diffRadius * pData->GetNumRows() +0.5F);
				do 
				{
					iOtherSamp = PickOtherSamp(pData, iRadius);
					pOtherTarget = *(pData->GetTargetExamples() + iOtherSamp);
					++cRetry;
				} while (*pOtherTarget == *pIO->m_pTarget && cRetry < s_cMaxRetry);
			}
		}
		else
		{
			TUPLE_DATA	tuple;

			if (SUCCEEDED(pDataTuple->GetNextIdx(pData->GetCurRow(), tuple)))
			{
				int iTuple = 0;

				if (s_cTupleSize > 1)
				{
					CDataTuple::Shuffle(tuple.m_vPairs);
					iOtherSamp = tuple.m_vPairs[iTuple++];
					iOtherSamp2 = tuple.m_vPairs[iTuple++];
					cOtherSamp = 2;
				}
				else
				{
					iOtherSamp = tuple.m_vPairs[iTuple++];
				}

			}
		}

		NREAL targetDiff = 0;

		if (cOtherSamp == 1)
		{
			targetDiff = AppendOneSample(pIO, pData, pThisTarget, iOtherSamp);
		}
		else
		{
			targetDiff = AppendTwoSamples(pIO, pData, pThisTarget, iOtherSamp, iOtherSamp2);
			NREAL	*pSrc = pIO->m_pInput + 3*pIO->m_cInput;

			if (3 == s_cExtraInput)
			{
				int iSrc = 0;
				pSrc[iSrc++] = L1Distance(pIO->m_pInput, pIO->m_pInput + pIO->m_cInput, pIO->m_cInput);
				pSrc[iSrc++] = L1Distance(pIO->m_pInput, pIO->m_pInput + 2*pIO->m_cInput, pIO->m_cInput);
				pSrc[0] = __max(pSrc[0], 1.0F);
				pSrc[iSrc] = (pSrc[0] - pSrc[1]) / pSrc[0];
				pSrc[iSrc] = __max(-3.0F, pSrc[iSrc]);
				pSrc[iSrc] = __min(3.0F, pSrc[iSrc]);
				pSrc[iSrc] *= 10000;

				if (true == s_bDoSampleSphere)
				{
					pData->SphereOneSample(pThis, pIO->m_pInput, pIO->m_cInput*3+s_cExtraInput,
						pData->GetMeans(), pData->GetStdev(), pData->GetInputRange(), pData->GetInputMin());
				}
			}
		}

		if (false == s_bUseAutoEncoder)
		{
			*pIO->m_pTarget= targetDiff;
		}
		else
		{
			pIO->m_pTarget = pIO->m_pInput;
			pIO->m_cTarget = pIO->m_cInput;
			//memcpy_s(pIO->m_pTarget, pIO->m_cTarget*sizeof(*pIO->m_pTarget), pIO->m_pInput, pIO->m_cTarget*sizeof(*pIO->m_pInput));
		}

		if (pIO->cExtraTargetLayers > 0 && NULL != pIO->m_ppExtraTargetLayers)
		{
			*pIO->m_ppExtraTargetLayers[0] = targetDiff;
		}

		hRet = S_OK;
	}

	return hRet;

}