示例#1
0
        public static double GetDistance(DistanceMeasure distanceMeasure, double x1, double y1, double x2, double y2)
        {
            switch (distanceMeasure)
            {
            case DistanceMeasure.Att:
                return(AttDistance(x1, y1, x2, y2));

            case DistanceMeasure.Direct:
                throw new ArgumentException("Direct distance measure requires distance matrix for distance calculation.");

            case DistanceMeasure.Euclidean:
                return(EuclideanDistance(x1, y1, x2, y2));

            case DistanceMeasure.Geo:
                return(GeoDistance(x1, y1, x2, y2));

            case DistanceMeasure.Manhattan:
                return(ManhattanDistance(x1, y1, x2, y2));

            case DistanceMeasure.Maximum:
                return(MaximumDistance(x1, y1, x2, y2));

            case DistanceMeasure.RoundedEuclidean:
                return(Math.Round(EuclideanDistance(x1, y1, x2, y2)));

            case DistanceMeasure.UpperEuclidean:
                return(Math.Ceiling(EuclideanDistance(x1, y1, x2, y2)));

            default:
                throw new InvalidOperationException("Distance measure is not known.");
            }
        }
示例#2
0
        private void RunHierarchicalCluster(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            DistanceMeasure distance = null;

            //distance.CalcDistMatrix(distance.structNames);
            // opt.hierarchical.atoms = PDB.PDBMODE.ALL_ATOMS;
            if (dcd != null)
            {
                distance = CreateMeasureForDCD(dcd, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryAglom,
                                               opt.hierarchical.alignmentFileName, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileAglom);
            }
            else
            {
                distance = CreateMeasure(name, dirName, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryAglom,
                                         alignFile, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileAglom);
            }

            DebugClass.WriteMessage("Measure Created");
            hierarchicalCluster hk = new hierarchicalCluster(distance, opt.hierarchical, dirName);

            if (beginJob != null)
            {
                beginJob(currentProcessName, hk.ToString(), dirName, distance.ToString());
            }
            clType = hk.ToString();
            ClusterOutput output;

            progressDic.Add(name, hk);
            distance.InitMeasure();
            DateTime cpuPart2 = DateTime.Now;

            output = hk.HierarchicalClustering(new List <string>(distance.structNames.Keys));
            UpdateOutput(name, dirName, alignFile, output, distance.ToString(), cpuPart1, cpuPart2, hk);
        }
示例#3
0
        private void RunFastHCluster(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            ClusterOutput   clustOut = null;
            DistanceMeasure distance = null;

            if (dcd == null)
            {
                distance = CreateMeasure(name, dirName, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryFast,
                                         alignFile, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileFast);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryFast,
                                               opt.hierarchical.alignmentFileName, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileFast);
            }

            FastDendrog km;

            km = new FastDendrog(distance, opt.hierarchical, dirName);
            if (beginJob != null)
            {
                beginJob(currentProcessName, km.ToString(), dirName, distance.ToString());
            }

            progressDic.Add(name, km);
            distance.InitMeasure();
            DateTime cpuPart2 = DateTime.Now;

            clType   = km.ToString();
            clustOut = km.Run(new List <string>(distance.structNames.Keys));
            UpdateOutput(name, dirName, alignFile, clustOut, distance.ToString(), cpuPart1, cpuPart2, km);
        }
示例#4
0
 public Jury3D(DistanceMeasure dMeasure)
 {
     this.dMeasure = dMeasure;
     maxV = 1;
     currentV = 0;
     
 }
示例#5
0
/*        private Dictionary<string,double> SableDist(List<string> refStructures)
 *      {
 *          StreamReader sableFile = new StreamReader(textBox3.Text);
 *          string line = sableFile.ReadLine();
 *          string prefix=refStructures[0];
 *          protInfo pr_SS=new protInfo();
 *          protInfo pr_SA = new protInfo();
 *          string seq, ss, sa;
 *          if(prefix.Contains("\\"))
 *          {
 *              string []aux=prefix.Split('\\');
 *              prefix=aux[aux.Length-2];
 *          }
 *          while (line !=null)
 *          {
 *              if(line.StartsWith("Query:"))
 *              {
 *                  string[] aux = line.Split(' ');
 *                  aux = aux[1].Split('.');
 *                  if (prefix.Contains(aux[0]))
 *                  {
 *                      pr_SS.sequence = sableFile.ReadLine();
 *                      string ww=sableFile.ReadLine();
 *                      pr_SS.profile = new List<byte>();
 *                      for (int i = 0; i < ww.Length;i++ )
 *                          pr_SS.profile.Add(ww[i].ToString());
 *                      line = sableFile.ReadLine();
 *                      pr_SA.sequence = pr_SS.sequence;
 *                      pr_SA.profile = new List<string>(Regex.Replace(sableFile.ReadLine(),@"\s+"," ").Trim().Split(' '));
 *                      for (int i = 0; i < pr_SA.profile.Count; i++)
 *                          pr_SA.profile[i] = (Convert.ToInt16(pr_SA.profile[i]) / 10).ToString();
 *
 *                  }
 *              }
 *              line = sableFile.ReadLine();
 *          }
 *
 *          sableFile.Close();
 *          Settings set=new Settings();
 *          set.Load();
 *          Alignment al=new Alignment(refStructures,set,"H:\\profiels\\SS3_SA9_internal.profiles");
 *          al.MyAlign(null);
 *          al.AddStructureToAlignment("sable_res","SS", ref pr_SS);
 *          al.AddStructureToAlignment("sable_res", "SA", ref pr_SA);
 *
 *          Dictionary<string, Dictionary<string, protInfo>> allProf = new Dictionary<string, Dictionary<string, protInfo>>();
 *          allProf.Add("SS", new Dictionary<string, protInfo>());
 *          allProf["SS"].Add("sable_res", pr_SS);
 *          allProf.Add("SA", new Dictionary<string, protInfo>());
 *          allProf["SA"].Add("sable_res", pr_SA);
 *          Dictionary<string,List<string>> protCombineStates = al.CombineProfiles("sable_res", allProf);
 *
 *
 *          JuryDistance dist = new JuryDistance(al, false);
 *
 *          Dictionary<string, double> distRes = new Dictionary<string, double>();
 *
 *          foreach (var item in refStructures)
 *          {
 *              distRes.Add(Path.GetFileName(item), dist.GetDistance("sable_res",Path.GetFileName(item)));
 *              currentV++;
 *          }
 *
 *
 *          return distRes;
 *
 *      }*/
        private DistanceMeasure PrepareDistanceMeasure(List <string> cluster, DistanceMeasures measure, string dirName)
        {
            DistanceMeasure distRes    = null;
            List <string>   clustFiles = new List <string>();

            foreach (var item in cluster)
            {
                clustFiles.Add(dirName + Path.DirectorySeparatorChar + item);
            }
            switch (measure)
            {
            case DistanceMeasures.HAMMING:
                distRes = new JuryDistance(clustFiles, alignFile, true, distanceControl1.profileName);
                break;

            case DistanceMeasures.MAXSUB:
            {
                distRes = new MaxSub(clustFiles, alignFile, distanceControl1.reference);
            }
            break;

            case DistanceMeasures.RMSD:
                distRes = new Rmsd(clustFiles, alignFile, distanceControl1.reference, distanceControl1.CAtoms, distanceControl1.referenceProfile);
                break;
            }
            distRes.InitMeasure();
            return(distRes);
        }
示例#6
0
        private static double GetDistance(int i, int j, DistanceMeasure distanceMeasure, double[,] coordinates, double[,] distances)
        {
            switch (distanceMeasure)
            {
            case DistanceMeasure.Att:
                return(AttDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]));

            case DistanceMeasure.Direct:
                return(distances[i, j]);

            case DistanceMeasure.Euclidean:
                return(EuclideanDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]));

            case DistanceMeasure.Geo:
                return(GeoDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]));

            case DistanceMeasure.Manhattan:
                return(ManhattanDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]));

            case DistanceMeasure.Maximum:
                return(MaximumDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]));

            case DistanceMeasure.RoundedEuclidean:
                return(Math.Round(EuclideanDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1])));

            case DistanceMeasure.UpperEuclidean:
                return(Math.Ceiling(EuclideanDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1])));

            default:
                throw new InvalidOperationException("Distance measure is not known.");
            }
        }
示例#7
0
 public void SetGeoCode(ICoordinates coordinates, int radius, DistanceMeasure measure)
 {
     GeoCode                 = _geoCodeUnityFactory.Create();
     GeoCode.Coordinates     = coordinates;
     GeoCode.Radius          = radius;
     GeoCode.DistanceMeasure = measure;
 }
示例#8
0
    public void setFont(Font font)
    {
        style.font = font;

        DistanceMeasure fontSize = null;

        if (font == CrhcConstants.FONT_NORMAL)
        {
            fontSize = CrhcConstants.FONT_HEIGHT_NORMAL;
        }
        else if (font == CrhcConstants.FONT_TITLE)
        {
            fontSize = CrhcConstants.FONT_HEIGHT_TITLE;
        }
        else if (font == CrhcConstants.FONT_SUBTITLE)
        {
            fontSize = CrhcConstants.FONT_HEIGHT_SUBTITLE;
        }
        else if (font == CrhcConstants.FONT_SOURCE)
        {
            fontSize = CrhcConstants.FONT_HEIGHT_SOURCE;
        }

        if (fontSize != null)
        {
            style.fontSize = (int)fontSize.getAs(NumberType.PIXELS);
        }

        //invalidateHeight();
    }
        public IList <TPredictionResult> Predict(IDataFrame queryDataFrame, IPredictionModel model, int dependentFeatureIndex)
        {
            ValidateModel(model);
            var knnModel               = model as IKnnPredictionModel <TPredictionResult>;
            var results                = new ConcurrentBag <RowIndexDistanceDto <TPredictionResult> >();
            var normalizedData         = NormalizeData(queryDataFrame, knnModel, dependentFeatureIndex);
            var normalizedTrainingData = normalizedData.Item1;
            var queryMatrix            = normalizedData.Item2;

            Parallel.For(0, queryDataFrame.RowCount, queryRowIdx =>
            {
                var rowVector = queryMatrix.Row(queryRowIdx);
                var distances = new ConcurrentBag <RowIndexDistanceDto <TPredictionResult> >();
                for (int trainingRowIdx = 0; trainingRowIdx < normalizedTrainingData.RowCount; trainingRowIdx++)
                {
                    var trainingRow = normalizedTrainingData.Row(trainingRowIdx);
                    TPredictionResult dependentFeatureValue = knnModel.ExpectedTrainingOutcomes[trainingRowIdx];
                    double distance = DistanceMeasure.Distance(rowVector, trainingRow);
                    var distanceDto = new RowIndexDistanceDto <TPredictionResult>(trainingRowIdx, distance, dependentFeatureValue);
                    distances.Add(distanceDto);
                }
                var sortedDistances = distances.OrderBy(distDto => distDto.Distance).Take(knnModel.KNeighbors);
                var result          = new RowIndexDistanceDto <TPredictionResult>(queryRowIdx, 0, _resultHandler(sortedDistances, WeightingFunction));
                results.Add(result);
            });
            return(results.OrderBy(res => res.RowIndex).Select(res => res.DependentFeatureValue).ToList());
        }
示例#10
0
        private DistanceMeasure CreateMeasureForDCD(DCDFile dcd, DistanceMeasures measure, PDB.PDBMODE atoms, bool jury1d, string alignFileName,
                                                    string profileName = null, string refJuryProfile = null)
        {
            DistanceMeasure dist = null;

            switch (measure)
            {
            case DistanceMeasures.HAMMING:
                if (refJuryProfile == null || !jury1d)
                {
                    throw new Exception("Sorry but for jury measure you have to define 1djury profile to find reference structure");
                }
                else
                {
                    dist = new JuryDistance(dcd, alignFileName, true, profileName, refJuryProfile);
                }
                break;

            case DistanceMeasures.RMSD:
                dist = new Rmsd(dcd, alignFileName, jury1d, atoms, refJuryProfile);
                break;

            case DistanceMeasures.MAXSUB:
                dist = new MaxSub(dcd, alignFileName, jury1d, refJuryProfile);
                break;

            case DistanceMeasures.GDT_TS:
                dist = new GDT_TS(dcd, alignFileName, jury1d, refJuryProfile);
                break;
            }

            dist.InitMeasure();
            return(dist);
        }
示例#11
0
       int GetDist(DistanceMeasures distance,string dirName,string item1,string item2)
       {
           DistanceMeasure dist = null;
           List<string> targets = new List<string>();


           if(!item1.Contains(dirName))
            targets.Add(dirName + Path.DirectorySeparatorChar + item1);
           else
            targets.Add(item1);
           targets.Add(dirName + Path.DirectorySeparatorChar + item2);

           switch (distance)
           {
               case DistanceMeasures.HAMMING:
                   dist = new JuryDistance(targets, "", false, "");
                   break;
               case DistanceMeasures.MAXSUB:
                   dist = new MaxSub(targets, "", false);
                   break;
               case DistanceMeasures.RMSD:
                   dist = new Rmsd(targets, "", false, PDB.PDBMODE.ONLY_CA);
                   break;
               case DistanceMeasures.GDT_TS:
                   dist = new GDT_TS(targets, "", false);
                   break;
           }
           dist.InitMeasure();          
           return GetDist(dist, item1, item2);
       }
示例#12
0
        private void RunBakerCluster(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            ClusterOutput   output   = null;
            DistanceMeasure distance = null;

            if (dcd == null)
            {
                distance = CreateMeasure(name, dirName, opt.threshold.hDistance, opt.threshold.hAtoms, opt.threshold.reference1Djury,
                                         alignFile, opt.threshold.hammingProfile, null);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.threshold.hDistance, opt.threshold.hAtoms, opt.threshold.reference1Djury,
                                               opt.threshold.alignmentFileName, opt.threshold.hammingProfile, null);
            }

            ThresholdCluster bk = new ThresholdCluster(distance, opt.threshold.distThresh, opt.threshold.bakerNumberofStruct);

            if (beginJob != null)
            {
                beginJob(currentProcessName, bk.ToString(), dirName, distance.ToString());
            }


            progressDic.Add(name, bk);
            distance.InitMeasure();
            DateTime cpuPart2 = DateTime.Now;

            clType = bk.ToString();
            output = bk.OrgClustering();
            UpdateOutput(name, dirName, alignFile, output, distance.ToString(), cpuPart1, cpuPart2, bk);
        }
示例#13
0
 public hierarchicalCluster(DistanceMeasure dMeasure, HierarchicalCInput hier, string dirName)
 {
     this.dMeasure    = dMeasure;
     this.linkageType = hier.linkageType;
     this.dirName     = dirName;
     progressRead     = 0;
     hierOpt          = hier;
 }
示例#14
0
 int GetDist(DistanceMeasure distance, string item1, string item2)
 {
     string[] aux1 = item1.Split(Path.DirectorySeparatorChar);
     string[] aux2 = item2.Split(Path.DirectorySeparatorChar);
     int v = distance.GetDistance(aux1[aux1.Length - 1], aux2[aux2.Length - 1]);
     if (v == distance.errorValue)
         v = errorValue;
     return v;
 }
示例#15
0
        public ThresholdCluster(DistanceMeasure dMeasure, float threshold, int minCluster)
        {
            this.dMeasure   = dMeasure;
            this.threshold  = threshold * 100;
            this.minCluster = minCluster;


            //dist = cBase.CalcRmsd(cBase.structNames);
        }
示例#16
0
 public FastDendrog(DistanceMeasure dMeasure, HierarchicalCInput input, string dirName)
 {
     this.dMeasure     = dMeasure;
     this.initNodesNum = input.numInitNodes;
     this.linkage      = input.linkageType;
     this.useKMeans    = input.ItMeans;
     this.hConcensus   = input.HConsensus;
     this.kMeansIter   = input.ItNum;
     this.dirName      = dirName;
     this.input        = input;
 }
示例#17
0
        /// <summary>
        /// Initialize class that performs multivariate DTW calculation for given series and settings.
        /// </summary>
        /// <param name="seriesVariables">Array of series value pairs for different variables with additional options for data preprocessing and weights.</param>
        /// <param name="distanceMeasure">Distance measure used (how distance for value pair (p,q) of signal elements is calculated from multiple variables).</param>
        /// <param name="boundaryConstraintStart">Apply boundary constraint at (1, 1).</param>
        /// <param name="boundaryConstraintEnd">Apply boundary constraint at (m, n).</param>
        /// <param name="slopeStepSizeDiagonal">Diagonal steps in local window for calculation. Results in Ikatura paralelogram shaped dtw-candidate space. Use in combination with slopeStepSizeAside parameter. Leave null for no constraint.</param>
        /// <param name="slopeStepSizeAside">Side steps in local window for calculation. Results in Ikatura paralelogram shaped dtw-candidate space. Use in combination with slopeStepSizeDiagonal parameter. Leave null for no constraint.</param>
        /// <param name="sakoeChibaMaxShift">Sakoe-Chiba max shift constraint (side steps). Leave null for no constraint.</param>
        public Dtw(SeriesVariable[] seriesVariables, DistanceMeasure distanceMeasure = DistanceMeasure.Euclidean, bool boundaryConstraintStart = true, bool boundaryConstraintEnd = true, int? slopeStepSizeDiagonal = null, int? slopeStepSizeAside = null, int? sakoeChibaMaxShift = null)
        {
            _seriesVariables = seriesVariables;
            _distanceMeasure = distanceMeasure;
            _boundaryConstraintStart = boundaryConstraintStart;
            _boundaryConstraintEnd = boundaryConstraintEnd;

            if (seriesVariables == null || seriesVariables.Length == 0)
                throw new ArgumentException("Series should have values for at least one variable.");

            for (int i = 1; i < _seriesVariables.Length; i++)
            {
                if (_seriesVariables[i].OriginalXSeries.Length != _seriesVariables[0].OriginalXSeries.Length)
                    throw new ArgumentException("All variables withing series should have the same number of values.");

                if (_seriesVariables[i].OriginalYSeries.Length != _seriesVariables[0].OriginalYSeries.Length)
                    throw new ArgumentException("All variables withing series should have the same number of values.");
            }

            _xLen = _seriesVariables[0].OriginalXSeries.Length;
            _yLen = _seriesVariables[0].OriginalYSeries.Length;

            if(_xLen == 0 || _yLen == 0)
                throw new ArgumentException("Both series should have at least one value.");

            if (sakoeChibaMaxShift != null && sakoeChibaMaxShift < 0)
                throw new ArgumentException("Sakoe-Chiba max shift value should be positive or null.");

            _isXLongerOrEqualThanY = _xLen >= _yLen;
            _signalsLengthDifference = Math.Abs(_xLen - _yLen);
            _sakoeChibaConstraint = sakoeChibaMaxShift.HasValue;
            _sakoeChibaMaxShift = sakoeChibaMaxShift.HasValue ? sakoeChibaMaxShift.Value : int.MaxValue;
            
            if (slopeStepSizeAside != null || slopeStepSizeDiagonal != null)
            {
                if (slopeStepSizeAside == null || slopeStepSizeDiagonal == null)
                    throw new ArgumentException("Both values or none for slope constraint must be specified.");

                if (slopeStepSizeDiagonal < 1)
                    throw new ArgumentException("Diagonal slope constraint parameter must be greater than 0.");

                if (slopeStepSizeAside < 0)
                    throw new ArgumentException("Diagonal slope constraint parameter must be greater or equal to 0.");

                _useSlopeConstraint = true;
                _slopeStepSizeAside = slopeStepSizeAside.Value;
                _slopeStepSizeDiagonal = slopeStepSizeDiagonal.Value;

                _slopeMatrixLookbehind = slopeStepSizeDiagonal.Value + slopeStepSizeAside.Value;
            }        
    
            //todo: throw error when solution (path from (1, 1) to (m, n) is not even possible due to slope constraints)
        }
示例#18
0
 public FastDendrog(DistanceMeasure dMeasure,HierarchicalCInput input,string dirName)
 {
     this.dMeasure = dMeasure;
     this.initNodesNum = input.numInitNodes;
     this.linkage = input.linkageType;
     this.useKMeans = input.ItMeans;
     this.hConcensus = input.HConsensus;
     this.kMeansIter = input.ItNum;
     this.dirName = dirName;
     this.input = input;
   
 }
示例#19
0
    /// <summary>
    /// If only the coordinates are given, can calculate the distance matrix.
    /// </summary>
    /// <returns>A full distance matrix between all cities.</returns>
    public static double[,] GetDistanceMatrix(DistanceMeasure distanceMeasure, double[,] coordinates, double[,] distances, int dimension) {
      if (distances != null) return distances;

      distances = new double[dimension, dimension];
      for (int i = 0; i < dimension - 1; i++)
        for (int j = i + 1; j < dimension; j++) {
          distances[i, j] = GetDistance(i, j, distanceMeasure, coordinates, distances);
          distances[j, i] = distances[i, j];
        }

      return distances;
    }
示例#20
0
        public override double GetDistance(AudioFeature f, AudioFeature.DistanceType t)
        {
            if (!(f is Scms))
            {
                new Exception("Can only handle AudioFeatures of type Scms, not of: " + f);
                return(-1);
            }
            Scms other = (Scms)f;

            DistanceMeasure distanceMeasure = DistanceMeasure.Euclidean;

            switch (t)
            {
            case AudioFeature.DistanceType.Dtw_Euclidean:
                distanceMeasure = DistanceMeasure.Euclidean;
                break;

            case AudioFeature.DistanceType.Dtw_SquaredEuclidean:
                distanceMeasure = DistanceMeasure.SquaredEuclidean;
                break;

            case AudioFeature.DistanceType.Dtw_Manhattan:
                distanceMeasure = DistanceMeasure.Manhattan;
                break;

            case AudioFeature.DistanceType.Dtw_Maximum:
                distanceMeasure = DistanceMeasure.Maximum;
                break;

            case AudioFeature.DistanceType.UCR_Dtw:
                return(UCRCSharp.UCR.DTW(this.GetArray(), other.GetArray()));

            case AudioFeature.DistanceType.CosineSimilarity:
                return(CosineSimilarity(this, other));

            case AudioFeature.DistanceType.BitStringHamming:
                return(Imghash.ImagePHash.HammingDistance(this.BitString, other.BitString));

            case AudioFeature.DistanceType.KullbackLeiblerDivergence:
            default:
                return(Distance(this, other, new ScmsConfiguration(Analyzer.MFCC_COEFFICIENTS)));
            }
            Dtw dtw = new Dtw(this.GetArray(), other.GetArray(), distanceMeasure, true, true, null, null, null);

            return(dtw.GetCost());
        }
示例#21
0
    // Note: The latitude/longitude order here is reversed compared to the various
    //       signatures in Tweetinvi (see the GeoCode constructor below for example),
    //       for ease of copy-and-pasting coordinates from the web
    static ISearchResult SearchTweetsTaggedWithGeo(string query,
                                                   double latitude,
                                                   double longitude,
                                                   double radius = 15,
                                                   DistanceMeasure distanceMeasure = DistanceMeasure.Miles)
    {
        var searchParameters = new TweetSearchParameters(query)
        {
            GeoCode = new GeoCode(longitude, latitude, radius, distanceMeasure),
            Lang = Language.English,
            SearchType = SearchResultType.Recent,
            MaximumNumberOfResults = 15,
            Locale = "new york"
        };

        return Search.SearchTweetsWithMetadata(searchParameters);
    }
示例#22
0
        private double Distance(double lat1, double lon1, double lat2, double lon2, DistanceMeasure unit)
        {
            double dist = Math.Sin(Deg2rad(lat1)) * Math.Sin(Deg2rad(lat2)) + Math.Cos(Deg2rad(lat1)) * Math.Cos(Deg2rad(lat2)) * Math.Cos(Deg2rad(lon1 - lon2));

            dist = Math.Acos(dist);
            dist = Rad2deg(dist);
            dist = dist * 60 * 1.1515;
            if (unit == DistanceMeasure.Kilometers)
            {
                dist = dist * 1.609344;
            }
            else if (unit == DistanceMeasure.Nautical)
            {
                dist = dist * 0.8684;
            }
            return(dist);
        }
示例#23
0
    // Note: The latitude/longitude order here is reversed compared to the various
    //       signatures in Tweetinvi (see the GeoCode constructor below for example),
    //       for ease of copy-and-pasting coordinates from the web
    static ISearchResult SearchTweetsTaggedWithGeo(string query,
                                                   double latitude,
                                                   double longitude,
                                                   double radius = 15,
                                                   DistanceMeasure distanceMeasure = DistanceMeasure.Miles)
    {
        var searchParameters = new TweetSearchParameters(query)
        {
            GeoCode                = new GeoCode(longitude, latitude, radius, distanceMeasure),
            Lang                   = Language.English,
            SearchType             = SearchResultType.Recent,
            MaximumNumberOfResults = 15,
            Locale                 = "new york"
        };

        return(Search.SearchTweetsWithMetadata(searchParameters));
    }
示例#24
0
        private void RunKMeans(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            ClusterOutput   clustOut;
            DistanceMeasure distance = null;

            if (dcd == null)
            {
                distance = CreateMeasure(name, dirName, opt.kmeans.kDistance, opt.kmeans.kAtoms, opt.kmeans.reference1Djury,
                                         alignFile, opt.kmeans.hammingProfile, opt.kmeans.jury1DProfile);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.kmeans.kDistance, opt.kmeans.kAtoms, opt.kmeans.reference1Djury,
                                               opt.kmeans.alignmentFileName, opt.kmeans.hammingProfile, opt.kmeans.jury1DProfile);
            }

            kMeans km;

            km = new kMeans(distance, opt.kmeans.kMeans_init);
            if (beginJob != null)
            {
                beginJob(currentProcessName, km.ToString(), dirName, distance.ToString());
            }

            progressDic.Add(name, km);
            distance.InitMeasure();
            DateTime cpuPart2 = DateTime.Now;

            clType = km.ToString();
            if ((int)opt.kmeans.maxK <= 1)
            {
                throw new Exception("k in k-Means must be bigger then 1, right now is: " + (int)opt.kmeans.maxK);
            }
            if (distance.structNames.Count < 10)
            {
                throw new Exception("Number of structures to cluster must be bigger then 10 right now is: " + distance.structNames.Count);
            }

            clustOut = km.kMeansLevel((int)opt.kmeans.maxK, opt.kmeans.maxIter, new List <string>(distance.structNames.Keys));
            UpdateOutput(name, dirName, alignFile, clustOut, distance.ToString(), cpuPart1, cpuPart2, km);
            GC.SuppressFinalize(distance);
        }
示例#25
0
        /// <summary>
        /// If only the coordinates are given, can calculate the distance matrix.
        /// </summary>
        /// <returns>A full distance matrix between all cities.</returns>
        public static double[,] GetDistanceMatrix(DistanceMeasure distanceMeasure, double[,] coordinates, double[,] distances, int dimension)
        {
            if (distances != null)
            {
                return(distances);
            }

            distances = new double[dimension, dimension];
            for (int i = 0; i < dimension - 1; i++)
            {
                for (int j = i + 1; j < dimension; j++)
                {
                    distances[i, j] = GetDistance(i, j, distanceMeasure, coordinates, distances);
                    distances[j, i] = distances[i, j];
                }
            }

            return(distances);
        }
示例#26
0
        public static Geopath CreateGeopath(BasicGeoposition center, double radius, DistanceMeasure units)
        {
            var earthRadius = (units == DistanceMeasure.Miles ? Geohelper.EarthRadiusInMiles : Geohelper.EarthRadiusInKilometers);
            var lat         = ToRadian(center.Latitude);  //radians
            var lng         = ToRadian(center.Longitude); //radians
            var d           = radius / earthRadius;       // d = angular distance covered on earth's surface
            var locations   = new List <BasicGeoposition>();

            for (var x = 0; x <= 360; x++)
            {
                var brng       = ToRadian(x);
                var latRadians = Math.Asin(Math.Sin(lat) * Math.Cos(d) + Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng));
                var lngRadians = lng + Math.Atan2(Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat), Math.Cos(d) - Math.Sin(lat) * Math.Sin(latRadians));

                locations.Add(new BasicGeoposition {
                    Latitude = ToDegrees(latRadians), Longitude = ToDegrees(lngRadians)
                });
            }

            return(new Geopath(locations));
        }
示例#27
0
        private void RunHKMeans(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuPart1 = DateTime.Now;
            ClusterOutput   clustOut = null;
            DistanceMeasure distance = null;

            if (dcd == null)
            {
                distance = CreateMeasure(name, dirName, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryKmeans,
                                         alignFile, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileKmeans);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.hierarchical.distance, opt.hierarchical.atoms, opt.hierarchical.reference1DjuryKmeans,
                                               opt.hierarchical.alignmentFileName, opt.hierarchical.hammingProfile, opt.hierarchical.jury1DProfileKmeans);
            }

            kMeans km;

            km = new kMeans(distance, true);
            if (beginJob != null)
            {
                beginJob(currentProcessName, km.ToString(), dirName, distance.ToString());
            }

            progressDic.Add(name, km);
            DateTime cpuPart2 = DateTime.Now;

            distance.InitMeasure();



            clType       = km.ToString();
            km.BMIndex   = opt.hierarchical.indexDB;
            km.threshold = opt.hierarchical.numberOfStruct;
            km.maxRepeat = opt.hierarchical.repeatTime;
            km.maxK      = opt.hierarchical.maxK;
            clustOut     = km.HierarchicalKMeans();
            UpdateOutput(name, dirName, alignFile, clustOut, distance.ToString(), cpuPart1, cpuPart2, km);
        }
示例#28
0
 private static double GetDistance(int i, int j, DistanceMeasure distanceMeasure, double[,] coordinates, double[,] distances) {
   switch (distanceMeasure) {
     case DistanceMeasure.Att:
       return AttDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]);
     case DistanceMeasure.Direct:
       return distances[i, j];
     case DistanceMeasure.Euclidean:
       return EuclideanDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]);
     case DistanceMeasure.Geo:
       return GeoDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]);
     case DistanceMeasure.Manhattan:
       return ManhattanDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]);
     case DistanceMeasure.Maximum:
       return MaximumDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]);
     case DistanceMeasure.RoundedEuclidean:
       return Math.Round(EuclideanDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]));
     case DistanceMeasure.UpperEuclidean:
       return Math.Ceiling(EuclideanDistance(coordinates[i, 0], coordinates[i, 1], coordinates[j, 0], coordinates[j, 1]));
     default:
       throw new InvalidOperationException("Distance measure is not known.");
   }
 }
示例#29
0
 public static double GetDistance(DistanceMeasure distanceMeasure, double x1, double y1, double x2, double y2) {
   switch (distanceMeasure) {
     case DistanceMeasure.Att:
       return AttDistance(x1, y1, x2, y2);
     case DistanceMeasure.Direct:
       throw new ArgumentException("Direct distance measure requires distance matrix for distance calculation.");
     case DistanceMeasure.Euclidean:
       return EuclideanDistance(x1, y1, x2, y2);
     case DistanceMeasure.Geo:
       return GeoDistance(x1, y1, x2, y2);
     case DistanceMeasure.Manhattan:
       return ManhattanDistance(x1, y1, x2, y2);
     case DistanceMeasure.Maximum:
       return MaximumDistance(x1, y1, x2, y2);
     case DistanceMeasure.RoundedEuclidean:
       return Math.Round(EuclideanDistance(x1, y1, x2, y2));
     case DistanceMeasure.UpperEuclidean:
       return Math.Ceiling(EuclideanDistance(x1, y1, x2, y2));
     default:
       throw new InvalidOperationException("Distance measure is not known.");
   }
 }
示例#30
0
       DistanceMeasure PrepareDistance(DistanceMeasures distance,List <string> targets,string alignFile,string profileName)
        {
            DistanceMeasure dist=null;
          
            switch (distance)
            {
                case DistanceMeasures.HAMMING:
                    dist = new JuryDistance(targets, alignFile, false, profileName);
                    break;
                case DistanceMeasures.MAXSUB:
                    dist = new MaxSub(targets, alignFile, false);
                    break;
                case DistanceMeasures.RMSD:
                    dist = new Rmsd(targets, alignFile, false, PDB.PDBMODE.ONLY_CA);
                    break;
                case DistanceMeasures.GDT_TS:
                    dist = new GDT_TS(targets, alignFile, false);
                    break;
            }

            dist.InitMeasure();
            return dist;
        }
示例#31
0
        private double CalcDevCluster(DistanceMeasure dd, List <string> cluster, string refStruct)
        {
            double sum = 0;
            double v1 = 0, v2 = 0;

            if (dd == null)
            {
                dd = PrepareDistanceMeasure(cluster, distanceControl1.distDef, dirName);
            }

            foreach (var item in cluster)
            {
                int x = dd.GetDistance(refStruct, item) / 100;
                v1 += x;
                v2 += x * x;
            }
            v1  = v1 / cluster.Count;
            v1 *= v1;
            v2  = v2 / cluster.Count;
            sum = Math.Sqrt(v2 - v1);

            return(sum);
        }
示例#32
0
        /// <summary>Get Distance</summary>
        /// <seealso cref="">comirva.audio.feature.AudioFeature#GetDistance(comirva.audio.feature.AudioFeature)</seealso>
        public override double GetDistance(AudioFeature f, AudioFeature.DistanceType t)
        {
            if (!(f is MandelEllis))
            {
                new Exception("Can only handle AudioFeatures of type Mandel Ellis, not of: " + f);
                return(-1);
            }
            MandelEllis other = (MandelEllis)f;

            DistanceMeasure distanceMeasure = DistanceMeasure.Euclidean;

            switch (t)
            {
            case AudioFeature.DistanceType.Dtw_Euclidean:
                distanceMeasure = DistanceMeasure.Euclidean;
                break;

            case AudioFeature.DistanceType.Dtw_SquaredEuclidean:
                distanceMeasure = DistanceMeasure.SquaredEuclidean;
                break;

            case AudioFeature.DistanceType.Dtw_Manhattan:
                distanceMeasure = DistanceMeasure.Manhattan;
                break;

            case AudioFeature.DistanceType.Dtw_Maximum:
                distanceMeasure = DistanceMeasure.Maximum;
                break;

            case AudioFeature.DistanceType.KullbackLeiblerDivergence:
            default:
                return(KullbackLeibler(this.gmmMe, other.gmmMe) + KullbackLeibler(other.gmmMe, this.gmmMe));
            }
            Dtw dtw = new Dtw(this.GetArray(), other.GetArray(), distanceMeasure, true, true, null, null, null);

            return(dtw.GetCost());
        }
示例#33
0
        private void Run3DJury(string name, string dirName, string alignFile = null, DCDFile dcd = null)
        {
            DateTime        cpuStart = DateTime.Now;
            ClusterOutput   output;
            DistanceMeasure distance = null;

            if (alignFile != null)
            {
                distance = CreateMeasure(name, null, opt.other.oDistance, opt.other.oAtoms, opt.other.reference1Djury,
                                         alignFile, opt.other.hammingProfile, opt.other.referenceProfile);
            }
            else
            if (dirName != null)
            {
                distance = CreateMeasure(name, dirName, opt.other.oDistance, opt.other.oAtoms, opt.other.reference1Djury,
                                         alignFile, opt.other.hammingProfile, opt.other.referenceProfile);
            }
            else
            {
                distance = CreateMeasureForDCD(dcd, opt.other.oDistance, opt.other.oAtoms, opt.other.reference1Djury,
                                               opt.other.alignFileName, opt.other.hammingProfile, opt.other.referenceProfile);
            }
            Jury3D ju = new Jury3D(distance);

            if (beginJob != null)
            {
                beginJob(currentProcessName, ju.ToString(), dirName, distance.ToString());
            }

            progressDic.Add(name, ju);
            distance.InitMeasure();
            clType = ju.ToString();
            output = ju.Run3DJury();
            UpdateOutput(name, dirName, alignFile, output, distance.ToString(), cpuStart, DateTime.Now, ju);
            progressDic.Remove(name);
        }
示例#34
0
 string CLusterRepresent(DistanceMeasure distance, List<string> targets)
 {           
     return distance.GetReferenceStructure(targets);
 }
示例#35
0
 public static ITweetSearchParameters GenerateSearchTweetParameter(ICoordinates coordinates, int radius, DistanceMeasure measure)
 {
     return(SearchQueryGenerator.GenerateSearchTweetParameter(coordinates, radius, measure));
 }
示例#36
0
        public void CalcStat()
        {
            
            List<string> fileNames = new List<string>();
            List<string> refStructures = new List<string>();
            DistanceMeasures measure = distanceControl1.distDef;
            DistanceMeasure distTemp = null;
            double distRes=0;
            maxV = selected.Count;
            distList.Clear();
            try
            {

                tableRes = new DataTable();

                tableRes.Columns.Add("Cluster Size", typeof(int));
                tableRes.Columns.Add("Reference structure", typeof(string));
                tableRes.Columns.Add("Distance", typeof(double));
                tableRes.Columns.Add("Hidden1", typeof(int));
                tableRes.Columns.Add("Hidden2", typeof(string));


                if (checkBoxSable.Checked)
                {
                    tableRes.Columns.Add("Dist to Sable", typeof(double));
                    maxV *= 2;
                }
                if (checkBox1.Checked)
                {
                    for (int i = 0; i < selected.Count; i++)
                        maxV += selected[i].Count;
                }
                fileNames.Add(textBox1.Text);

                jury1D jury = new jury1D();
                if (distanceControl1.reference)
                    jury.PrepareJury(dirName, alignFile, distanceControl1.referenceProfile);

                refStructures.Clear();
                selected.Sort(delegate(List<string> first, List<string> second)
                { return first.Count.CompareTo(second.Count); });

                selected.Reverse();
                //    dataGridView1.Rows.Add(selected.Count);

                for (int i = 0; i < selected.Count; i++)
                {
                    string refD = selected[i][0];
                    ClusterOutput juryO = null;
                    if (distanceControl1.reference)
                    {

                        if (selected[i].Count > 5)
                        {
                            juryO = jury.JuryOptWeights(selected[i]);
                            if (juryO == null)
                                continue;
                            refD = juryO.juryLike[0].Key;
                            if (!fileNames.Contains(dirName + Path.DirectorySeparatorChar + juryO.juryLike[0].Key))
                            {
                                fileNames.Add(dirName + Path.DirectorySeparatorChar + juryO.juryLike[0].Key);
                                refStructures.Add(dirName + Path.DirectorySeparatorChar + refD);
                            }
                        }
                        else
                            if (!fileNames.Contains(dirName + Path.DirectorySeparatorChar + selected[i][0]))
                            {
                                fileNames.Add(dirName + Path.DirectorySeparatorChar + selected[i][0]);
                                refStructures.Add(dirName + Path.DirectorySeparatorChar + selected[i][0]);
                            }

                    }
                    else
                    {

                        dist = PrepareDistanceMeasure(selected[i], measure, dirName);
                        distTemp = dist;
                        refD = dist.GetReferenceStructure(selected[i]);
                        fileNames.Add(dirName + Path.DirectorySeparatorChar + refD);
                        refStructures.Add(dirName + Path.DirectorySeparatorChar + refD);
                    }

                    if (fileNames.Count == 2)
                    {
                        switch (measure)
                        {
                            case DistanceMeasures.HAMMING:
                                dist = new JuryDistance(fileNames, alignFile, false, distanceControl1.profileName);
                                break;
                            case DistanceMeasures.MAXSUB:
                                dist = new MaxSub(fileNames, null, false);
                                break;
                            case DistanceMeasures.RMSD:
                                dist = new Rmsd(fileNames, null, false, distanceControl1.CAtoms);
                                break;

                        }
                        dist.InitMeasure();
                        distRes = Convert.ToDouble(String.Format("{0:0.00}", dist.GetDistance(native, refD) / 100.0));
                    }
                    fileNames.RemoveAt(fileNames.Count - 1);
                    if (checkBoxSable.Checked && refStructures.Count > 0)
                        tableRes.Rows.Add(selected[i].Count, refD, distRes, i, dirName, 0.0);
                    else
                        tableRes.Rows.Add(selected[i].Count, refD, distRes, i, dirName);
                    currentV++;
                }
                if (checkBoxSable.Checked && refStructures.Count > 0)
                {
                    Dictionary<string, double> res = null;// SableDist(refStructures);
                    for (int i = 0; i < refStructures.Count; i++)
                    {
                        if (res.ContainsKey(Path.GetFileName(refStructures[i])))
                        {
                            DataRow dr = tableDist.Rows[i];                            
                            dr[5] = Convert.ToDouble(String.Format("{0:0.00}", res[Path.GetFileName(refStructures[i])]));
                        }
                    }
                }
                if (checkBox1.Checked)
                {
                    CalculateDistToAll();
                }

            }
            catch(Exception ex)
            {
                exc = ex;
            }
        }
示例#37
0
 /// <summary>
 /// Initialize class that performs single variable DTW calculation for given series and settings.
 /// </summary>
 /// <param name="x">Series A, array of values.</param>
 /// <param name="y">Series B, array of values.</param>
 /// /// <param name="distanceMeasure">Distance measure used (how distance for value pair (p,q) of signal elements is calculated from multiple variables).</param>
 /// <param name="boundaryConstraintStart">Apply boundary constraint at (1, 1).</param>
 /// <param name="boundaryConstraintEnd">Apply boundary constraint at (m, n).</param>
 /// <param name="slopeStepSizeDiagonal">Diagonal steps in local window for calculation. Results in Ikatura paralelogram shaped dtw-candidate space. Use in combination with slopeStepSizeAside parameter. Leave null for no constraint.</param>
 /// <param name="slopeStepSizeAside">Side steps in local window for calculation. Results in Ikatura paralelogram shaped dtw-candidate space. Use in combination with slopeStepSizeDiagonal parameter. Leave null for no constraint.</param>
 /// <param name="sakoeChibaMaxShift">Sakoe-Chiba max shift constraint (side steps). Leave null for no constraint.</param>
 public Dtw(double[] x, double[] y, DistanceMeasure distanceMeasure = DistanceMeasure.Euclidean, bool boundaryConstraintStart = true, bool boundaryConstraintEnd = true, int? slopeStepSizeDiagonal = null, int? slopeStepSizeAside = null, int? sakoeChibaMaxShift = null)
     : this(new [] { new SeriesVariable(x, y) }, distanceMeasure, boundaryConstraintStart, boundaryConstraintEnd, slopeStepSizeDiagonal, slopeStepSizeAside, sakoeChibaMaxShift)
 {
     
 }
示例#38
0
		//private jury1D jury;

		public hierarchicalCluster (DistanceMeasure dMeasure, AglomerativeType linkageType,string dirName)
		{
			this.dMeasure=dMeasure;
            this.linkageType = linkageType;
            this.dirName = dirName;
		}
示例#39
0
 public GeoCode(double longitude, double latitude, double radius, DistanceMeasure distanceMeasure)
 {
     Coordinates = new Coordinates(longitude, latitude);
     Radius = radius;
     DistanceMeasure = distanceMeasure;
 }
示例#40
0
 public static IGeoCode GenerateGeoCode(ICoordinates coordinates, double radius, DistanceMeasure measure)
 {
     return _geoFactory.GenerateGeoCode(coordinates, radius, measure);
 }
 public ITweetSearchParameters CreateSearchTweetParameter(double longitude, double latitude, int radius, DistanceMeasure measure)
 {
     return new TweetSearchParameters(longitude, latitude, radius, measure);
 }
 public void SetGeoCode(double longitude, double latitude, double radius, DistanceMeasure measure)
 {
     GeoCode = new GeoCode(longitude, latitude, radius, measure);
 }
示例#43
0
         public ClusterOutput DendrogUsingMeasures(List<string> structures)
         {
             jury1D juryLocal = new jury1D();
             juryLocal.PrepareJury(al);
             
             ClusterOutput outC = null;
             Dictionary<string, List<int>> dic;
             //Console.WriteLine("Start after jury " + Process.GetCurrentProcess().PeakWorkingSet64);
             maxV = 4;
             currentV = 0;
             dic = PrepareKeys(structures,false);
             
             currentV++;
             //DebugClass.DebugOn();
             //dic = HashEntropyCombine(dic, structures,input.reqClusters);
             //Console.WriteLine("Entropy ready after jury " + Process.GetCurrentProcess().PeakWorkingSet64);
             DebugClass.WriteMessage("Entropy ready");
             //Alternative way to start of UQclust Tree must be finished
             //input.relClusters = 10000;
             input.relClusters = input.reqClusters;
             input.perData = 90;
             //dic = FastCombineKeys(dic, structures, false);
             dic = FastCombineKeys(dic, structures, true);
             DebugClass.WriteMessage("dic size" + dic.Count);
             currentV++;
             
             //Console.WriteLine("Combine ready after jury " + Process.GetCurrentProcess().PeakWorkingSet64);
             DebugClass.WriteMessage("Combine Keys ready");
             Dictionary<string, string> translateToCluster = new Dictionary<string, string>(dic.Count);
             List<string> structuresToDendrogram = new List<string>(dic.Count);
             List<string> structuresFullPath = new List<string>(dic.Count);
             DebugClass.WriteMessage("Number of clusters: "+dic.Count);
             int cc = 0;
             foreach (var item in dic)
             {
                 if (item.Value.Count > 2)
                 {
                     List<string> cluster = new List<string>(item.Value.Count);
                     foreach (var str in item.Value)
                         cluster.Add(structures[str]);


                     ClusterOutput output = juryLocal.JuryOptWeights(cluster);

                     structuresToDendrogram.Add(output.juryLike[0].Key);
                     if(alignFile==null)
                        structuresFullPath.Add(dirName + Path.DirectorySeparatorChar + output.juryLike[0].Key);
                     else
                         structuresFullPath.Add(output.juryLike[0].Key);
                     translateToCluster.Add(output.juryLike[0].Key, item.Key);
                 }
                 else
                 {
                     structuresToDendrogram.Add(structures[item.Value[0]]);
                     if(alignFile==null)
                        structuresFullPath.Add(dirName + Path.DirectorySeparatorChar + structures[item.Value[0]]);
                     else
                         structuresFullPath.Add(structures[item.Value[0]]);
                     translateToCluster.Add(structures[item.Value[0]], item.Key);
                 }
                 cc++;
             }
             currentV++;
             DebugClass.WriteMessage("Jury finished");
             switch (dMeasure)
             {
                 case DistanceMeasures.HAMMING:
                     if (refJuryProfile == null || !jury1d)
                         throw new Exception("Sorry but for jury measure you have to define 1djury profile to find reference structure");
                     else
                         dist = new JuryDistance(structuresFullPath, alignFile, true, profileName, refJuryProfile);
                     break;


                 case DistanceMeasures.COSINE:
                     dist = new CosineDistance(structuresFullPath, alignFile, jury1d, profileName, refJuryProfile);
                     break;

                 case DistanceMeasures.RMSD:
                     dist = new Rmsd(structuresFullPath, "", jury1d, atoms, refJuryProfile);
                     break;
                 case DistanceMeasures.MAXSUB:
                     dist = new MaxSub(structuresFullPath, "", jury1d, refJuryProfile);
                     break;
             }

            // return new ClusterOutput();
             DebugClass.WriteMessage("Start hierarchical");
             //Console.WriteLine("Start hierarchical " + Process.GetCurrentProcess().PeakWorkingSet64);
             currentV = maxV;
             hk = new hierarchicalCluster(dist, linkageType, dirName);
             dist.InitMeasure();
            
             //Now just add strctures to the leaves             
             outC = hk.HierarchicalClustering(structuresToDendrogram);
             DebugClass.WriteMessage("Stop hierarchical");
             List<HClusterNode> hLeaves = outC.hNode.GetLeaves();

             foreach(var item in hLeaves)
             {
                 if (translateToCluster.ContainsKey(item.setStruct[0]))
                 {
                     foreach (var str in dic[translateToCluster[item.setStruct[0]]])
                         if (item.setStruct[0] != structures[str])
                            item.setStruct.Add(structures[str]);
                 }
                 else
                     throw new Exception("Cannot add structure. Something is wrong");
             }
             outC.hNode.RedoSetStructures();

             return outC;
         }
 public void SetGeoCode(ICoordinates coordinates, double radius, DistanceMeasure measure)
 {
     GeoCode = new GeoCode(coordinates, radius, measure);
 }
 public TweetSearchParameters(double longitude, double latitude, int radius, DistanceMeasure measure) : this()
 {
     GeoCode = new GeoCode(longitude, latitude, radius, measure);
 }
 public TweetSearchParameters(ICoordinates coordinates, int radius, DistanceMeasure measure) : this()
 {
     GeoCode = new GeoCode(coordinates, radius, measure);
 }
示例#47
0
 public static ITweetSearchParameters GenerateSearchTweetParameter(double longitude, double latitude, int radius, DistanceMeasure measure)
 {
     return(SearchQueryGenerator.GenerateSearchTweetParameter(longitude, latitude, radius, measure));
 }
        private PoolItem GetBestItem(IList <PoolItem> items, CombinatorialSemantics semantics, DistanceMeasure distanceMeasure)
        {
            double   bestDistance = Double.MaxValue;
            PoolItem bestItem     = null;
            var      allSemantics = items.Where(item => item is ISemanticsHolder && ((ISemanticsHolder)item.Node).SemanticsEvaluated)
                                    .Select(item => ((ISemanticsHolder)item.Node).Semantics);

            foreach (var item in items)
            {
                var semanticsNode = item.Node as ISemanticsHolder;
                if (semanticsNode != null && semanticsNode.SemanticsEvaluated)
                {
                    var distance = distanceMeasure(semantics, semanticsNode.Semantics, allSemantics);
                    if (distance < bestDistance)
                    {
                        bestDistance = distance;
                        bestItem     = item;
                    }
                }
            }
            return(bestItem);
        }
 public ITweetSearchParameters CreateSearchTweetParameter(ICoordinates coordinates, int radius, DistanceMeasure measure)
 {
     return new TweetSearchParameters(coordinates, radius, measure);
 }
示例#50
0
        private double CalcDevCluster(DistanceMeasure dd, List<string> cluster, string refStruct)
        {            
            double sum = 0;
            double v1 = 0, v2 = 0;

            if(dd==null)
                dd = PrepareDistanceMeasure(cluster, distanceControl1.distDef, dirName);

            foreach (var item in cluster)
            {
                int x = dd.GetDistance(refStruct, item) / 100;
                v1 += x;
                v2 += x * x;

            }
            v1 = v1 / cluster.Count;
            v1 *= v1;
            v2 = v2 / cluster.Count;
            sum = Math.Sqrt(v2 - v1);

            return sum;
        }
示例#51
0
    // Note: The latitude/longitude order here is reversed compared to the various
    //       signatures in Tweetinvi (see the GeoCode constructor below for example),
    //       for ease of copy-and-pasting coordinates from the web
    static ISearchResult SearchTweetsTaggedWithGeo(string query,
												   double latitude,
												   double longitude,
												   double radius = 15,
												   DistanceMeasure distanceMeasure = DistanceMeasure.Miles)
    {
        var searchParameters = new TweetSearchParameters(query)
        {
            GeoCode = new GeoCode(longitude, latitude, radius, distanceMeasure),
            Lang = Language.English,
            SearchType = SearchResultType.Recent,
            MaximumNumberOfResults = 15
        };

        try
        {
            var result = Search.SearchTweetsWithMetadata(searchParameters);
            return result;
        }
        catch (Exception e)
        {
            PrintStackTrace(e);
            Log(e);
            return null;
        }
    }
示例#52
0
        private void CalculateDistToAll()
        {
            tableDist = new DataTable();
            tableDist.Columns.Add("Reference structure", typeof(string));
            tableDist.Columns.Add("Distance", typeof(double));
            tableDist.Columns.Add("Cluster size", typeof(int));

            List <string> fileNames=new List<string>();
            if (textBox1.Text != null && textBox1.Text.Length > 5 && File.Exists(textBox1.Text))
            {
                fileNames.Add(textBox1.Text);
                string[] tmp = textBox1.Text.Split(Path.DirectorySeparatorChar);
                native = tmp[tmp.Length - 1];
            }

            bestStr = float.MaxValue;
            foreach (var item in selected)
            {
                foreach (var lItem in item)
                {
                    fileNames.Add(dirName+Path.DirectorySeparatorChar+lItem);
                    switch (distanceControl1.distDef)
                    {
                        case DistanceMeasures.HAMMING:
                            dist = new JuryDistance(fileNames, alignFile, false, distanceControl1.profileName);
                            break;
                        case DistanceMeasures.MAXSUB:
                            dist = new MaxSub(fileNames, alignFile, false);
                            break;
                        case DistanceMeasures.RMSD:
                            dist = new Rmsd(fileNames, alignFile, false, distanceControl1.CAtoms);                           
                            break;
                    }
                    dist.InitMeasure();
                    float distF = float.MaxValue;
                    if (distanceControl1.distDef != DistanceMeasures.HAMMING)
                    {
                        if (!dist.pdbs.molDic.ContainsKey(native) || !dist.pdbs.molDic.ContainsKey(lItem))
                            continue;

                        if (dist.pdbs.molDic[native].mol.Chains[0].chainSequence.Length > dist.pdbs.molDic[lItem].mol.Chains[0].chainSequence.Length)
                            distF = dist.GetDistance(native, lItem) / 100.0f;
                        else
                            distF = dist.GetDistance(lItem, native) / 100.0f;
                    }
                    else
                        distF=dist.GetDistance(native, lItem) / 100.0f;

                    tableDist.Rows.Add(lItem, Convert.ToDouble(String.Format("{0:0.00}", distF)),item.Count);
                    distList.Add(lItem, distF);
                    if (bestStr > distF)
                        bestStr = distF;
                    fileNames.RemoveAt(fileNames.Count - 1);
                    currentV++;
                }
            }

        }
示例#53
0
 public static ITweetSearchParameters CreateTweetSearchParameter(ICoordinates coordinates, int radius, DistanceMeasure measure)
 {
     return SearchQueryParameterGenerator.CreateSearchTweetParameter(coordinates, radius, measure);
 }
示例#54
0
 public GeoCode(ICoordinates coordinates, double radius, DistanceMeasure distanceMeasure)
 {
     Coordinates = coordinates;
     Radius = radius;
     DistanceMeasure = distanceMeasure;
 }
示例#55
0
        public void SetGeoCode(double longitude, double latitude, int radius, DistanceMeasure measure)
        {
            var coordinates = _geoFactory.GenerateCoordinates(longitude, latitude);

            SetGeoCode(coordinates, radius, measure);
        }
示例#56
0
 public static ITweetSearchParameters CreateTweetSearchParameter(double longitude, double latitude, int radius, DistanceMeasure measure)
 {
     return SearchQueryParameterGenerator.CreateSearchTweetParameter(longitude, latitude, radius, measure);   
 }
示例#57
0
        public void GetFraction(object param)
        {

            float fraction = 0;
            float avrDiff=0;
            int counter = 0;
            int end;
            DistanceMeasures distance=((fractionParams)param).distance;
            string profileName = ((fractionParams)param).profileName;
            double distThreshold = ((fractionParams)param).distThreshold;
            int clustersNum = ((fractionParams)param).clustersNum;

            results = new DataTable();
            try
            {
                DataColumn col;
                col=results.Columns.Add("Output", typeof(string));
                col.AllowDBNull = true;
                col=results.Columns.Add("Best Model", typeof(string));
                col.AllowDBNull = true;
                col=results.Columns.Add("Distance To Native", typeof(double));
                col.AllowDBNull = true;
                col=results.Columns.Add("Best found", typeof(string));
                col.AllowDBNull = true;
                col=results.Columns.Add("Distance to best model", typeof(double));
                col.AllowDBNull = true;

                maxV = output.Count;
                foreach (var item in output)
                {
                    string[] kkk = item.dirName.Split(Path.DirectorySeparatorChar);
                    List<List<string>> clusters = item.GetClusters(10);

                    List<string> list = new List<string>();

                    foreach (var cl in clusters)
                        foreach (var target in cl)
                            list.Add(target);


                    string native = item.dirName + ".pdb";
                    if (item.dirName.Contains("."))
                    {
                        string[] aux = item.dirName.Split('.');
                        native = aux[0] + ".pdb";
                    }



                    string fileBestModel = item.dirName + "_" + distance.ToString() + "_bestmodel.dat";
                    BestModel bestToNative;
                    if (!File.Exists(fileBestModel))
                    {
                        bestToNative = FindBestToModel(list, distance, item.dirName, "", "", native);
                        StreamWriter st = new StreamWriter(fileBestModel);
                        st.WriteLine(bestToNative.modelName + " " + bestToNative.value);
                        st.Close();
                    }
                    else
                    {
                        StreamReader st = new StreamReader(fileBestModel);
                        string line = st.ReadLine();
                        string[] aux = line.Split(' ');
                        bestToNative.modelName = aux[0];
                        bestToNative.value = Convert.ToInt32(aux[1]);
                        st.Close();
                    }

                    if (bestToNative.value == int.MaxValue)
                        continue;

                   // list.Clear();

                    if (clusters.Count > 0)
                        clusters.Sort(delegate(List<string> first, List<string> second)
                        { return second.Count.CompareTo(first.Count); });

                    string represent = "";
                    //And now best five
                    
                    BestModel vOut = new BestModel();
                    InitBestModel(distance, ref vOut);
                    end = clustersNum;
                    if (clusters.Count < clustersNum)
                        end = clusters.Count;
                    for (int i = 0; i < end; i++)
                    //for (int i = 0; i < clusters.Count; i++)
                    {
                        if (profileName != null)
                            represent = CLusterRepresentJury(item.dirName, clusters[i], profileName)[0].Key;
                        else
                        {
                            if (item.juryLike != null)
                                represent = item.juryLike[i].Key;
                            else
                            {
                               /* if (clusters.Count > 1)
                                {
                                    represent = CLusterRepresent(distance,item.dirName, clusters[i],"",profileName);                             
                                }
                                else*/
                                    represent = clusters[i][0];
                            }
                        }
                        //int vDist = GetDist(distance, item.dirName, bestToNative.modelName, represent);
                        int vDist = GetDist(distance, item.dirName, native, represent);
                        CheckBest(distance, vDist, represent, ref vOut);

                    }

                    if (bestToNative.value == errorValue || vOut.value == errorValue)
                    {
                        if (bestToNative.value == errorValue && vOut.value != errorValue)
                            results.Rows.Add(item.name, bestToNative.modelName, double.NaN, vOut.modelName, vOut.value / 100.0);
                        else
                            if(bestToNative.value != errorValue && vOut.value == errorValue)
                                results.Rows.Add(item.name, bestToNative.modelName, bestToNative.value / 100.0, vOut.modelName, double.NaN);
                            else
                                results.Rows.Add(item.name, bestToNative.modelName, double.NaN, vOut.modelName, double.NaN);
                    }
                    else
                        results.Rows.Add(item.name, bestToNative.modelName, bestToNative.value / 100.0, vOut.modelName, vOut.value / 100.0);
                    if (vOut.value!=errorValue && Math.Abs(vOut.value-bestToNative.value) < distThreshold * 100)
                    {
                        fraction++;
                    }
                    if (vOut.value!=errorValue)
                    {
                        counter++;
                        avrDiff += vOut.value;
                    }
                    dist = null;
                    GC.Collect();

                    currentV++;

                }
                avrDiff /= counter;
                fraction /= counter;
                results.Rows.Add(null, null, null, null, null);
                results.Rows.Add("AVR:"," "+Math.Round(avrDiff / 100,2),null,"Fraction:",Math.Round(fraction,2));
            }
            catch(Exception ex)
            {
                exc = ex;
            }
           //Console.WriteLine("avrDiff=" + avrDiff + " fraction=" + fraction+" pearson="+Pearson());
            currentV = maxV;
        }
示例#58
0
       string CLusterRepresent(DistanceMeasures distance,string dirName, List<string> targets,string alignFile, string profileName)
        {
            DistanceMeasure dist;
            List<string> fileNames=new List<string>();

            foreach (var item in targets)
                fileNames.Add(dirName + Path.DirectorySeparatorChar + item);
            dist = PrepareDistance(distance, fileNames, alignFile, profileName);
            return dist.GetReferenceStructure(targets);
        }
示例#59
0
        public kMeans(DistanceMeasure dMeasure,bool hierarchical=false)
        {
            this.dMeasure = dMeasure;
//            this.initialization = initialization;
            this.hierarchical = hierarchical;
        }
示例#60
0
 public IGeoCode GenerateGeoCode(ICoordinates coordinates, double radius, DistanceMeasure measure)
 {
     return new GeoCode(coordinates, radius, measure);
 }