Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SheafBuildingExample.ipynb breaks #34

Open
mszulcz-mitre opened this issue Sep 20, 2024 · 0 comments
Open

SheafBuildingExample.ipynb breaks #34

mszulcz-mitre opened this issue Sep 20, 2024 · 0 comments

Comments

@mszulcz-mitre
Copy link
Collaborator

Cell 8 in SheafBuildingExample.ipynb breaks. The problem seems to be a change in ComputeConsistency() and the default for an attribute of the Cell class.

In an older version of the code, Cell in pysheaf.py had the attribute mExtendedAssignmentConsistancyWeightDivisor that was defaulted to 2.0. In the new version, it's replaced with mExtendedAssignmentConsistancyWeight that's defaulted to None. As a result, the code tries compute a norm on an empty array on Line 181 of pysheaf.py in ComputeConsistency()

      if self.mExtendedAssignmentConsistancyWeight is not None:
         for current_assignment_index in range(len(tmp_assignments)):
            for test_assignment_index in range(len(tmp_assignments)):
               if current_assignment_index != test_assignment_index:
                  assignment_comparisions.append(self.Compare(tmp_assignments[current_assignment_index].mValue,tmp_assignments[test_assignment_index].mValue)*self.mExtendedAssignmentConsistancyWeight)
      
      return np.linalg.norm(np.array(assignment_comparisions,dtype='float'),ord=numpyNormType) # ComputeConsistency

One fix is to add this to Cell 8:

shf.GetCell('C').mExtendedAssignmentConsistancyWeight = 0.5

But that's probably not enough. The criteria to compute consistencies should also probably change (see last line):

def AbleToComputeConsistency(self):
      multiple_extended_assignments = (len(self.mExtendedAssignments) > 1)
      data_and_extended_assignments = self.mDataAssignmentPresent and (len(self.mExtendedAssignments) != 0)
      return (multiple_extended_assignments and self.mExtendedAssignmentConsistancyWeight!=None) or data_and_extended_assignments # AbleToComputeConsistency

The code also should probably check that a norm isn't computed on an empty list:

   def ComputeLocalConsistencyRadius(self,cellIndices=None):
      """
      This method will call compute consistency on all cells (default) or those specified by cellIndices in the sheaf. 
      The default behavior is to then return the max error. This can be changed by setting mNumpyNormType

      :returns: consistency radius of the sheaf assignment
      """
      if cellIndices is None:
         cell_index_list = self.nodes()
      else:
         cell_index_list = cellIndices

      cell_consistancies_list = []
      for cell_index in cell_index_list:
         if self.GetCell(cell_index).AbleToComputeConsistency() == True:
            if cellIndices is None:
               cell_consistancies_list.append(self.GetCell(cell_index).ComputeConsistency(self.mNumpyNormType))
            else:
               cell_consistancies_list.append(self.GetCell(cell_index).ComputeConsistency(self.mNumpyNormType, cellStartIndices=cellIndices))

      if len(cell_consistancies_list)>0:
         return np.linalg.norm(cell_consistancies_list,ord=self.mNumpyNormType) # ComputeConsistencyRadius
      else: 
         return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant