private void TestInterpolation( PairR[] pairs, float expectedR, Int32 indexOfInterpolatedR )
 {
     InterpolateR target = new InterpolateR(pairs);
     Int32 subjectTag1 = pairs[indexOfInterpolatedR].SubjectTag1;
     Int32 subjectTag2 = pairs[indexOfInterpolatedR].SubjectTag2;
     float? actualRV1 = target.Interpolate(subjectTag1, subjectTag2);
     Assert.AreEqual(expectedR, actualRV1, "The interpolated R should be correct.");
     float actualRV2 = pairs[indexOfInterpolatedR].R.Value;
     Assert.AreEqual(expectedR, actualRV2, "The interpolated R should be correct.");
 }
示例#2
0
        public static PairR[] BuildRelatedPairsOfGen1Housemates( DataColumn dcPass1, Int32 subjectTag1, Int32 subjectTag2, Int32 extendedID, LinksDataSet ds )
        {
            if ( CommonCalculations.GenerationOfSubjectTag(subjectTag1) != Generation.Gen1 ) throw new ArgumentOutOfRangeException("The generation implied by subjectTag1 isn't Gen1.");
            if ( CommonCalculations.GenerationOfSubjectTag(subjectTag2) != Generation.Gen1 ) throw new ArgumentOutOfRangeException("The generation implied by subjectTag2 isn't Gen1.");
            if ( dcPass1 == null ) throw new ArgumentNullException("dcPass1");
            switch ( dcPass1.ColumnName ) {
                case "RImplicitPass1":
                case "RExplicitPass1":
                case "RPass1":
                    break;
                default:
                    throw new ArgumentOutOfRangeException("dcPass1", dcPass1, "The column wasn't recognized as a valid 'Pass1' column.");
            }

            if ( ds == null ) throw new ArgumentNullException("ds");
            string select = string.Format("{0}={1} AND {2}={3} AND ({4}={5} OR {6}={7} OR {6}={5} OR {4}={7}) AND {5}<{7}",
                extendedID, ds.tblRelatedStructure.ExtendedIDColumn.ColumnName,
                (byte)RelationshipPath.Gen1Housemates, ds.tblRelatedStructure.RelationshipPathColumn.ColumnName,
                subjectTag1, ds.tblRelatedStructure.SubjectTag_S1Column.ColumnName,
                subjectTag2, ds.tblRelatedStructure.SubjectTag_S2Column.ColumnName);
            LinksDataSet.tblRelatedStructureRow[] drsStructure = (LinksDataSet.tblRelatedStructureRow[])ds.tblRelatedStructure.Select(select);
            Trace.Assert(drsStructure.Length >= 1, "At least one record should be returned.");

            PairR[] pairs = new PairR[drsStructure.Length];
            for ( Int32 i = 0; i < drsStructure.Length; i++ ) {
                LinksDataSet.tblRelatedStructureRow dr = drsStructure[i];
                Int32 relatedID = dr.ID;
                LinksDataSet.tblRelatedValuesRow drValue = ds.tblRelatedValues.FindByID(relatedID);
                float? pass1;
                if ( DBNull.Value.Equals(drValue[dcPass1]) )//if ( drValue.IsRImplicitPass1Null() )
                    pass1 = null;
                else
                    pass1 = Convert.ToSingle(drValue[dcPass1]);//pass1 = (float)drValue.RImplicitPass1;
                pairs[i] = new PairR(dr.SubjectTag_S1, dr.SubjectTag_S2, relatedID, pass1);
            }
            return pairs;
        }
示例#3
0
 public bool Equals( PairR other )
 {
     if ( SubjectTag1 != other.SubjectTag1 )
         return false;
     else if ( SubjectTag2 != other.SubjectTag2 )
         return false;
     else if ( R.HasValue != other.R.HasValue )
         return false;
     else if ( R.HasValue && R.Value == other.R.Value )
         return false;
     else if ( IsInterpolated == other.IsInterpolated )
         return false;
     else
         return true;
 }
示例#4
0
 public static Int32 CountHalfSibs( PairR[] pairs )
 {
     Int32 tally = 0;
     foreach ( PairR pair in pairs ) {
         if (pair.R.HasValue &&  Math.Abs(pair.R.Value - RCoefficients.SiblingHalf) < 1e-5 )
             tally += 1;
     }
     return tally;
 }
 private bool HasLargeMetaphoricalDistance( PairR[] pairs )
 {
     if ( _drSubjectDetails1.IsMobNull() || _drSubjectDetails2.IsMobNull() )
         return false;
     double mobDifferenceInYears = Math.Abs(_drSubjectDetails1.Mob.Subtract(_drSubjectDetails2.Mob).TotalDays / Constants.DaysPerYear);
     if ( mobDifferenceInYears > 8 && PairR.CountHalfSibs(pairs) >= 2 )
         return true;
     else if ( mobDifferenceInYears > 5 && PairR.CountHalfSibs(pairs) >= 3 )
         return true;
     else
         return false;
 }
 private static void CompareRImplicit( PairR[] pairs )
 {
     foreach( PairR pair in pairs ) {
         double? actualRImplicit = RetrieveRImplicit(pair.SubjectTag1, pair.SubjectTag2);
         if( !actualRImplicit.HasValue )
             Assert.Fail(string.Format("Subjects {0} and {1} had a null RImplicit.  It should be {2}.", pair.SubjectTag1, pair.SubjectTag2, pair.R));
         else
             Assert.AreEqual(pair.R, actualRImplicit, "The RImplicit for subject tags " + pair.SubjectTag1 + " and " + pair.SubjectTag2 + " should be equal.");
     }
 }