Best Python code snippet using robotframework-appiumlibrary_python
models.py
Source:models.py
...203 ["planned_end", "id"],204 ["actual_end", "id"],205 ["end_date", "id"],206 ]207 def get_activity(self):208 return self209 def is_valid_iati(self):210 """211 Check if all required foreign objects are created212 """213 # TODO: create this method - 2016-10-03214 return True215 @property216 def get_providing_activities(self):217 providing_activities = []218 for transaction in self.transaction_set.all():219 if (220 transaction.provider_organisation221 and transaction.provider_organisation.provider_activity222 ):223 providing_activities.append(224 transaction.provider_organisation.provider_activity.id225 )226 return Activity.objects.filter(227 id__in=providing_activities228 ).exclude(id=self.id).distinct()229 @property230 def get_provided_activities(self):231 return Activity.objects.filter(232 transaction__provider_organisation__provider_activity=self.id233 ).exclude(234 id=self.id235 ).distinct()236class ActivityDefaultAidType(models.Model):237 activity = models.ForeignKey(238 Activity,239 on_delete=models.CASCADE,240 related_name='default_aid_types'241 )242 aid_type = models.ForeignKey(AidType, on_delete=models.CASCADE)243 def __string__(self, ):244 return "%s - %s" % (self.activity.id, self.aid_type.code)245def value_decimal_field():246 return models.DecimalField(247 max_digits=15,248 decimal_places=2,249 null=True,250 blank=True,251 db_index=True,252 )253def value_currency_field():254 return models.CharField(255 max_length=3,256 null=True,257 default=None,258 blank=True,259 )260class AbstractActivityAggregation(models.Model):261 budget_value = value_decimal_field()262 budget_currency = value_currency_field()263 disbursement_value = value_decimal_field()264 disbursement_currency = value_currency_field()265 incoming_funds_value = value_decimal_field()266 incoming_funds_currency = value_currency_field()267 commitment_value = value_decimal_field()268 commitment_currency = value_currency_field()269 expenditure_value = value_decimal_field()270 expenditure_currency = value_currency_field()271 interest_payment_value = value_decimal_field()272 interest_payment_currency = value_currency_field()273 loan_repayment_value = value_decimal_field()274 loan_repayment_currency = value_currency_field()275 reimbursement_value = value_decimal_field()276 reimbursement_currency = value_currency_field()277 purchase_of_equity_value = value_decimal_field()278 purchase_of_equity_currency = value_currency_field()279 sale_of_equity_value = value_decimal_field()280 sale_of_equity_currency = value_currency_field()281 credit_guarantee_value = value_decimal_field()282 credit_guarantee_currency = value_currency_field()283 incoming_commitment_value = value_decimal_field()284 incoming_commitment_currency = value_currency_field()285 outgoing_pledge_value = value_decimal_field()286 outgoing_pledge_currency = value_currency_field()287 incoming_pledge_value = value_decimal_field()288 incoming_pledge_currency = value_currency_field()289 # Add usd converted value option to the aggregations290 budget_value_usd = value_decimal_field()291 disbursement_value_usd = value_decimal_field()292 incoming_funds_value_usd = value_decimal_field()293 commitment_value_usd = value_decimal_field()294 expenditure_value_usd = value_decimal_field()295 interest_payment_value_usd = value_decimal_field()296 loan_repayment_value_usd = value_decimal_field()297 reimbursement_value_usd = value_decimal_field()298 purchase_of_equity_value_usd = value_decimal_field()299 sale_of_equity_value_usd = value_decimal_field()300 credit_guarantee_value_usd = value_decimal_field()301 incoming_commitment_value_usd = value_decimal_field()302 outgoing_pledge_value_usd = value_decimal_field()303 incoming_pledge_value_usd = value_decimal_field()304 # Add gbp converted value option to the aggregations305 budget_value_gbp = value_decimal_field()306 disbursement_value_gbp = value_decimal_field()307 incoming_funds_value_gbp = value_decimal_field()308 commitment_value_gbp = value_decimal_field()309 expenditure_value_gbp = value_decimal_field()310 interest_payment_value_gbp = value_decimal_field()311 loan_repayment_value_gbp = value_decimal_field()312 reimbursement_value_gbp = value_decimal_field()313 purchase_of_equity_value_gbp = value_decimal_field()314 sale_of_equity_value_gbp = value_decimal_field()315 credit_guarantee_value_gbp = value_decimal_field()316 incoming_commitment_value_gbp = value_decimal_field()317 outgoing_pledge_value_gbp = value_decimal_field()318 incoming_pledge_value_gbp = value_decimal_field()319 class Meta:320 abstract = True321 index_together = [322 ["budget_value", "activity"],323 ["disbursement_value", "activity"],324 ["incoming_funds_value", "activity"],325 ["commitment_value", "activity"],326 ["expenditure_value", "activity"],327 ["interest_payment_value", "activity"],328 ["loan_repayment_value", "activity"],329 ["reimbursement_value", "activity"],330 ["purchase_of_equity_value", "activity"],331 ["sale_of_equity_value", "activity"],332 ["credit_guarantee_value", "activity"],333 ["incoming_commitment_value", "activity"],334 ["outgoing_pledge_value", "activity"],335 ["incoming_pledge_value", "activity"]336 ]337class ActivityAggregation(AbstractActivityAggregation):338 activity = models.OneToOneField(339 Activity, related_name="activity_aggregation",340 default=None, on_delete=models.CASCADE)341class ChildAggregation(AbstractActivityAggregation):342 activity = models.OneToOneField(343 Activity, related_name="child_aggregation", default=None,344 on_delete=models.CASCADE)345class ActivityPlusChildAggregation(AbstractActivityAggregation):346 activity = models.OneToOneField(347 Activity,348 related_name="activity_plus_child_aggregation",349 default=None, on_delete=models.CASCADE)350class Title(models.Model):351 narratives = GenericRelation(352 Narrative,353 content_type_field='related_content_type',354 object_id_field='related_object_id')355 # related name allows title to be accessed from activity.title356 activity = models.OneToOneField(Activity, related_name="title",357 on_delete=models.CASCADE)358 def get_activity(self):359 return self.activity360 def __unicode__(self,):361 return "Title"362class ActivitySearchData(models.Model):363 activity = models.OneToOneField(Activity, on_delete=models.CASCADE)364 search_identifier = models.CharField(db_index=True, max_length=150)365 search_description = models.TextField(max_length=80000)366 search_title = models.TextField(max_length=80000)367 search_country_name = models.TextField(max_length=80000)368 search_region_name = models.TextField(max_length=80000)369 search_sector_name = models.TextField(max_length=80000)370 search_participating_organisation_name = models.TextField(max_length=80000)371 search_reporting_organisation_name = models.TextField(max_length=80000)372 search_documentlink_title = models.TextField(max_length=80000)373class ActivityReportingOrganisation(models.Model):374 ref = models.CharField(max_length=250, db_index=True)375 normalized_ref = models.CharField(376 max_length=120, db_index=True, default="", blank=True)377 narratives = GenericRelation(378 Narrative,379 content_type_field='related_content_type',380 object_id_field='related_object_id')381 activity = models.ForeignKey(382 Activity,383 related_name="reporting_organisations", on_delete=models.CASCADE)384 # if in organisation standard385 organisation = models.ForeignKey(386 Organisation,387 null=True,388 default=None,389 on_delete=models.SET_NULL)390 type = models.ForeignKey(391 OrganisationType, null=True, default=None, blank=True,392 on_delete=models.CASCADE393 )394 secondary_reporter = models.BooleanField(default=False)395 class Meta:396 verbose_name = 'Reporting organisation'397 verbose_name_plural = 'Reporting organisations'398 def __unicode__(self,):399 return "ref: %s" % self.ref400 def get_activity(self):401 return self.activity402class ActivityParticipatingOrganisation(models.Model):403 ref = models.CharField(max_length=250, null=True, default=None)404 normalized_ref = models.CharField(405 blank=True,406 max_length=120,407 null=True,408 default=None,409 db_index=True)410 activity = models.ForeignKey(411 Activity,412 related_name="participating_organisations", on_delete=models.CASCADE)413 # if in organisation standard414 organisation = models.ForeignKey(415 Organisation,416 null=True,417 blank=True,418 default=None,419 on_delete=models.SET_NULL)420 type = models.ForeignKey(OrganisationType,421 null=True, blank=True,422 default=None, on_delete=models.CASCADE)423 role = models.ForeignKey(OrganisationRole,424 null=True, blank=True,425 default=None, on_delete=models.CASCADE)426 # when organisation is not mentioned in transactions427 org_activity_id = models.CharField(428 max_length=150, blank=False, null=True, db_index=True)429 org_activity_obj = models.ForeignKey(430 Activity,431 related_name="participating_activity",432 null=True,433 default=None, on_delete=models.CASCADE)434 narratives = GenericRelation(435 Narrative,436 content_type_field='related_content_type',437 object_id_field='related_object_id')438 # TODO: Workaround for IATI ref limitation - 2015-11-26439 primary_name = models.TextField(blank=True)440 crs_channel_code = models.ForeignKey(441 CRSChannelCode,442 null=True,443 on_delete=models.CASCADE444 )445 def __unicode__(self,):446 return "name: %s - role: %s" % (self.primary_name, self.role)447 class Meta:448 verbose_name = 'Participating organisation'449 verbose_name_plural = 'Participating organisations'450 def get_activity(self):451 return self.activity452class ActivityPolicyMarker(models.Model):453 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)454 code = models.ForeignKey(PolicyMarker, on_delete=models.CASCADE)455 vocabulary = models.ForeignKey(PolicyMarkerVocabulary,456 on_delete=models.CASCADE)457 vocabulary_uri = models.URLField(null=True, blank=True)458 significance = models.ForeignKey(459 PolicySignificance,460 null=True,461 blank=True,462 on_delete=models.CASCADE463 )464 narratives = GenericRelation(465 Narrative,466 content_type_field='related_content_type',467 object_id_field='related_object_id')468 def __unicode__(self,):469 return "code: %s - significance: %s" % (470 self.code, self.significance.code471 )472 class Meta:473 verbose_name = 'Policy marker'474 verbose_name_plural = 'Policy markers'475 def get_activity(self):476 return self.activity477class ActivitySector(models.Model):478 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)479 sector = models.ForeignKey(Sector, on_delete=models.CASCADE)480 vocabulary = models.ForeignKey(SectorVocabulary,481 null=True, blank=True,482 default=None, on_delete=models.CASCADE)483 vocabulary_uri = models.URLField(null=True, blank=True)484 percentage = models.CharField(max_length=100, null=True, blank=True)485 narratives = GenericRelation(486 Narrative,487 content_type_field='related_content_type',488 object_id_field='related_object_id')489 def __unicode__(self,):490 return "name: %s" % self.sector.name491 class Meta:492 verbose_name = 'Sector'493 verbose_name_plural = 'Sectors'494 def get_activity(self):495 return self.activity496class ActivityRecipientCountry(models.Model):497 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)498 country = models.ForeignKey(Country, on_delete=models.CASCADE)499 percentage = models.CharField(max_length=100, null=True, blank=True)500 narratives = GenericRelation(501 Narrative,502 content_type_field='related_content_type',503 object_id_field='related_object_id')504 def __unicode__(self,):505 return "name: %s" % self.country.name506 class Meta:507 verbose_name = 'Recipient country'508 verbose_name_plural = 'Recipient countries'509 def get_activity(self):510 return self.activity511class CountryBudgetItem(models.Model):512 activity = models.OneToOneField(513 Activity, related_name="country_budget_items",514 on_delete=models.CASCADE)515 vocabulary = models.ForeignKey(BudgetIdentifierVocabulary,516 on_delete=models.CASCADE)517 def get_activity(self):518 return self.activity519class HumanitarianScope(models.Model):520 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)521 code = models.CharField(max_length=100)522 vocabulary = models.ForeignKey(HumanitarianScopeVocabulary,523 on_delete=models.CASCADE)524 vocabulary_uri = models.URLField(null=True, blank=True)525 type = models.ForeignKey(HumanitarianScopeType, on_delete=models.CASCADE)526 narratives = GenericRelation(527 Narrative,528 content_type_field='related_content_type',529 object_id_field='related_object_id'530 )531 def get_activity(self):532 return self.activity533class BudgetItem(models.Model):534 country_budget_item = models.ForeignKey(CountryBudgetItem,535 on_delete=models.CASCADE)536 code = models.ForeignKey(BudgetIdentifier, on_delete=models.CASCADE)537 percentage = models.CharField(max_length=100, null=True, blank=True)538 def get_activity(self):539 return self.country_budget_item.activity540class BudgetItemDescription(models.Model):541 budget_item = models.OneToOneField(542 BudgetItem, related_name="description", on_delete=models.CASCADE)543 narratives = GenericRelation(544 Narrative,545 content_type_field='related_content_type',546 object_id_field='related_object_id')547 def get_activity(self):548 return self.budget_item.country_budget_item.activity549class ActivityRecipientRegion(models.Model):550 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)551 region = models.ForeignKey(Region, on_delete=models.CASCADE)552 vocabulary = models.ForeignKey(553 RegionVocabulary, default=1, on_delete=models.CASCADE)554 vocabulary_uri = models.URLField(null=True, blank=True)555 narratives = GenericRelation(556 Narrative,557 content_type_field='related_content_type',558 object_id_field='related_object_id')559 percentage = models.CharField(max_length=100, null=True, blank=True)560 def __unicode__(self,):561 return "name: %s" % self.region562 class Meta:563 verbose_name = 'Recipient region'564 verbose_name_plural = 'Recipient regions'565 def get_activity(self):566 return self.activity567class OtherIdentifier(models.Model):568 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)569 identifier = models.CharField(max_length=100)570 owner_ref = models.CharField(max_length=100, default="")571 # owner_name = models.CharField(max_length=100, default="")572 narratives = GenericRelation(573 Narrative,574 content_type_field='related_content_type',575 object_id_field='related_object_id')576 type = models.ForeignKey(577 OtherIdentifierType, null=True, blank=True, on_delete=models.CASCADE)578 def __unicode__(self,):579 return "identifier: %s" % self.identifier580 def get_activity(self):581 return self.activity582class ActivityWebsite(models.Model):583 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)584 url = models.URLField()585 def __unicode__(self,):586 return "%s" % self.url587 def get_activity(self):588 return self.activity589class ContactInfo(models.Model):590 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)591 type = models.ForeignKey(592 ContactType, null=True, blank=True, on_delete=models.CASCADE)593 telephone = models.CharField(594 max_length=100, default="", null=True, blank=True)595 email = models.TextField(default="", null=True, blank=True)596 website = models.CharField(597 max_length=255, default="", null=True, blank=True)598 def __unicode__(self,):599 return "type: %s" % self.type600 def get_activity(self):601 return self.activity602class ContactInfoOrganisation(models.Model):603 contact_info = models.OneToOneField(604 ContactInfo, related_name="organisation",605 default=None, on_delete=models.CASCADE)606 narratives = GenericRelation(607 Narrative,608 content_type_field='related_content_type',609 object_id_field='related_object_id')610class ContactInfoDepartment(models.Model):611 contact_info = models.OneToOneField(612 ContactInfo, related_name="department",613 default=None, on_delete=models.CASCADE)614 narratives = GenericRelation(615 Narrative,616 content_type_field='related_content_type',617 object_id_field='related_object_id')618 def get_activity(self):619 return self.contact_info.activity620class ContactInfoPersonName(models.Model):621 contact_info = models.OneToOneField(622 ContactInfo, related_name="person_name",623 default=None, on_delete=models.CASCADE)624 narratives = GenericRelation(625 Narrative,626 content_type_field='related_content_type',627 object_id_field='related_object_id')628 def get_activity(self):629 return self.contact_info.activity630class ContactInfoJobTitle(models.Model):631 contact_info = models.OneToOneField(632 ContactInfo, related_name="job_title",633 default=None, on_delete=models.CASCADE)634 narratives = GenericRelation(635 Narrative,636 content_type_field='related_content_type',637 object_id_field='related_object_id')638 def get_activity(self):639 return self.contact_info.activity640class ContactInfoMailingAddress(models.Model):641 contact_info = models.OneToOneField(642 ContactInfo, related_name="mailing_address",643 default=None, on_delete=models.CASCADE)644 narratives = GenericRelation(645 Narrative,646 content_type_field='related_content_type',647 object_id_field='related_object_id')648 def get_activity(self):649 return self.contact_info.activity650class RelatedActivity(models.Model):651 current_activity = models.ForeignKey(652 Activity,653 on_delete=models.CASCADE)654 ref_activity = models.ForeignKey(655 Activity,656 related_name="ref_activity",657 null=True,658 blank=True,659 on_delete=models.SET_NULL)660 type = models.ForeignKey(661 RelatedActivityType,662 max_length=200,663 null=True,664 blank=True,665 default=None, on_delete=models.CASCADE)666 ref = models.CharField(db_index=True, max_length=200,667 default="", blank=True)668 def __unicode__(self,):669 return "ref-activity: %s" % self.ref_activity670 class Meta:671 verbose_name_plural = "related activities"672 def get_activity(self):673 return self.current_activity674class DocumentLink(models.Model):675 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)676 result = models.ForeignKey('Result', null=True, on_delete=models.CASCADE)677 result_indicator = models.ForeignKey(678 'ResultIndicator',679 related_name='result_indicator_document_links',680 null=True,681 on_delete=models.CASCADE682 )683 result_indicator_baseline = models.ForeignKey(684 'ResultIndicatorBaseline',685 related_name='baseline_document_links',686 null=True,687 blank=True,688 on_delete=models.CASCADE689 )690 result_indicator_period_target = models.ForeignKey(691 'ResultIndicatorPeriodTarget',692 related_name='period_target_document_links',693 null=True,694 on_delete=models.CASCADE695 )696 result_indicator_period_actual = models.ForeignKey(697 'ResultIndicatorPeriodActual',698 related_name='period_actual_document_links',699 null=True,700 on_delete=models.CASCADE701 )702 url = models.TextField(max_length=500)703 file_format = models.ForeignKey(704 FileFormat, null=True, blank=True,705 default=None, on_delete=models.CASCADE)706 categories = models.ManyToManyField(707 DocumentCategory,708 through="DocumentLinkCategory")709 iso_date = models.DateField(null=True, blank=True)710 def __unicode__(self,):711 return "url: %s" % self.url712 def get_activity(self):713 return self.activity714# enables saving before parent object is saved (workaround)715# TODO: eliminate the need for this716class DocumentLinkCategory(models.Model):717 document_link = models.ForeignKey(DocumentLink, on_delete=models.CASCADE)718 category = models.ForeignKey(DocumentCategory, on_delete=models.CASCADE)719 class Meta:720 verbose_name_plural = "Document link categories"721 def get_activity(self):722 return self.document_link.activity723class DocumentLinkLanguage(models.Model):724 document_link = models.ForeignKey(DocumentLink, on_delete=models.CASCADE)725 language = models.ForeignKey(726 Language, null=True, blank=True,727 default=None, on_delete=models.CASCADE)728 def get_activity(self):729 return self.document_link.activity730class DocumentLinkTitle(models.Model):731 document_link = models.OneToOneField(732 DocumentLink, on_delete=models.CASCADE)733 narratives = GenericRelation(734 Narrative,735 content_type_field='related_content_type',736 object_id_field='related_object_id')737 def get_activity(self):738 return self.document_link.activity739class DocumentLinkDescription(models.Model):740 document_link = models.OneToOneField(741 DocumentLink, on_delete=models.CASCADE)742 narratives = GenericRelation(743 Narrative,744 content_type_field='related_content_type',745 object_id_field='related_object_id')746class DocumentSearch(models.Model):747 '''Currently this model is just stored for refference and searching (both748 feature and API endpoint) for Documents is disabled749 '''750 document = models.OneToOneField('Document', on_delete=models.CASCADE)751 content = VectorField()752 text = VectorField()753 last_reindexed = models.DateTimeField()754class Document(models.Model):755 document_link = models.OneToOneField(756 DocumentLink, on_delete=models.CASCADE)757 long_url = models.TextField(max_length=500, default='')758 url_is_valid = models.BooleanField(default=False)759 document_name = models.CharField(max_length=500, default='')760 is_downloaded = models.BooleanField(default=False)761 document_content = models.TextField(default='')762 long_url_hash = models.CharField(max_length=500, default='')763 file_hash = models.CharField(max_length=500, default='')764 document_or_long_url_changed = models.BooleanField(default=False)765 created_at = models.DateTimeField(auto_now_add=True)766 modified_at = models.DateTimeField(auto_now_add=True)767 def __unicode__(self):768 return self.id769 class Meta:770 ordering = ['id']771 verbose_name_plural = "documents"772 index_together = [773 ["created_at", "id"],774 ]775 def get_activity(self):776 return self.document_link.activity777class Result(models.Model):778 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)779 type = models.ForeignKey(780 ResultType, null=True, blank=True,781 default=None, on_delete=models.CASCADE)782 aggregation_status = models.BooleanField(default=False)783 def __unicode__(self,):784 return "Result"785 def get_activity(self):786 return self.activity787class ResultTitle(models.Model):788 result = models.OneToOneField(Result, on_delete=models.CASCADE)789 narratives = GenericRelation(790 Narrative,791 content_type_field='related_content_type',792 object_id_field='related_object_id')793 def get_activity(self):794 return self.result.activity795class ResultDescription(models.Model):796 result = models.OneToOneField(Result, on_delete=models.CASCADE)797 narratives = GenericRelation(798 Narrative,799 content_type_field='related_content_type',800 object_id_field='related_object_id')801 def get_activity(self):802 return self.result.activity803class ResultIndicator(models.Model):804 result = models.ForeignKey(Result, on_delete=models.CASCADE)805 measure = models.ForeignKey(806 IndicatorMeasure,807 null=True,808 blank=True,809 default=None, on_delete=models.CASCADE)810 ascending = models.BooleanField(default=True)811 aggregation_status = models.BooleanField(default=False)812 def get_activity(self):813 return self.result.activity814class ResultIndicatorBaseline(models.Model):815 result_indicator = models.ForeignKey(816 ResultIndicator,817 on_delete=models.CASCADE818 )819 year = models.IntegerField()820 value = models.CharField(821 null=True, blank=True, default=None, max_length=100)822 iso_date = models.DateField(null=True, blank=True)823 def __unicode__(self,):824 return "baseline year: %s" % self.year825class ResultReference(models.Model):826 result = models.ForeignKey(827 Result, on_delete=models.CASCADE)828 code = models.CharField(max_length=255)829 vocabulary = models.ForeignKey(830 ResultVocabulary, on_delete=models.CASCADE)831 vocabulary_uri = models.URLField(null=True, blank=True)832 def get_activity(self):833 return self.result.activity834class ResultIndicatorReference(models.Model):835 result_indicator = models.ForeignKey(836 ResultIndicator, on_delete=models.CASCADE)837 code = models.CharField(max_length=255)838 vocabulary = models.ForeignKey(839 IndicatorVocabulary, on_delete=models.CASCADE)840 # TODO: this should be renamed to vocabulary_uri in IATI standard...841 # - 2016-06-03:842 indicator_uri = models.URLField(null=True, blank=True)843 def get_activity(self):844 return self.result_indicator.result.activity845class ResultIndicatorTitle(models.Model):846 result_indicator = models.OneToOneField(847 ResultIndicator, on_delete=models.CASCADE)848 primary_name = models.CharField(849 max_length=255,850 null=False,851 blank=True,852 default="",853 db_index=True)854 narratives = GenericRelation(855 Narrative,856 content_type_field='related_content_type',857 object_id_field='related_object_id')858 def get_activity(self):859 return self.result_indicator.result.activity860class ResultIndicatorDescription(models.Model):861 result_indicator = models.OneToOneField(862 ResultIndicator, on_delete=models.CASCADE)863 narratives = GenericRelation(864 Narrative,865 content_type_field='related_content_type',866 object_id_field='related_object_id')867 def get_activity(self):868 return self.result_indicator.result.activity869class ResultIndicatorBaselineComment(models.Model):870 result_indicator_baseline = models.OneToOneField(871 ResultIndicatorBaseline,872 on_delete=models.CASCADE,873 )874 narratives = GenericRelation(875 Narrative,876 content_type_field='related_content_type',877 object_id_field='related_object_id')878 def get_activity(self):879 return self.result_indicator_baseline.result_indicator.result.activity880class ResultIndicatorPeriod(models.Model):881 result_indicator = models.ForeignKey(882 ResultIndicator, on_delete=models.CASCADE)883 period_start = models.DateField(null=True, blank=True)884 period_end = models.DateField(null=True, blank=True)885 def __unicode__(self,):886 return "target: %s, actual: %s" % (887 self.target.value if self.target else 'none',888 self.actual889 )890 def get_activity(self):891 return self.result_indicator.result.activity892class ResultIndicatorPeriodTarget(models.Model):893 value = models.CharField(894 max_length=50, blank=True, default=None, null=True)895 result_indicator_period = models.ForeignKey(896 ResultIndicatorPeriod,897 null=True,898 related_name='targets',899 on_delete=models.CASCADE900 )901 def __unicode__(self,):902 return "target: %s" % (self.value)903class ResultIndicatorPeriodActual(models.Model):904 value = models.CharField(905 max_length=50, blank=True, default=None, null=True)906 result_indicator_period = models.ForeignKey(907 ResultIndicatorPeriod,908 null=True,909 related_name='actuals',910 on_delete=models.CASCADE911 )912 def __unicode__(self,):913 return "actual: %s" % (self.value)914class ResultIndicatorPeriodTargetLocation(models.Model):915 result_indicator_period_target = models.ForeignKey(916 ResultIndicatorPeriodTarget, on_delete=models.CASCADE)917 ref = models.CharField(max_length=50)918 location = models.ForeignKey('Location', on_delete=models.CASCADE)919 def __unicode__(self,):920 return "%s" % self.ref921 # FIXME: fix all these methods and check if they are used922 def get_activity(self):923 return self.result_indicator_period.result_indicator.result.activity924class ResultIndicatorPeriodActualLocation(models.Model):925 result_indicator_period_actual = models.ForeignKey(926 ResultIndicatorPeriodActual, on_delete=models.CASCADE)927 ref = models.CharField(max_length=50)928 location = models.ForeignKey('Location', on_delete=models.CASCADE)929 def __unicode__(self,):930 return "%s" % self.ref931 def get_activity(self):932 return self.result_indicator_period.result_indicator.result.activity933class ResultIndicatorPeriodTargetDimension(models.Model):934 result_indicator_period_target = models.ForeignKey(935 ResultIndicatorPeriodTarget, on_delete=models.CASCADE)936 name = models.CharField(max_length=100)937 value = models.CharField(max_length=100)938 def __unicode__(self,):939 return "%s: %s" % (self.name, self.value)940 def get_activity(self):941 return self.result_indicator_period.result_indicator.result.activity942class ResultIndicatorPeriodActualDimension(models.Model):943 result_indicator_period_actual = models.ForeignKey(944 ResultIndicatorPeriodActual, on_delete=models.CASCADE)945 name = models.CharField(max_length=100)946 value = models.CharField(max_length=100)947 def __unicode__(self,):948 return "%s: %s" % (self.name, self.value)949 def get_activity(self):950 return self.result_indicator_period.result_indicator.result.activity951class ResultIndicatorBaselineDimension(models.Model):952 result_indicator_baseline = models.ForeignKey(953 ResultIndicatorBaseline,954 on_delete=models.CASCADE,955 )956 name = models.CharField(max_length=100)957 value = models.CharField(max_length=100)958 def __unicode__(self,):959 return "%s: %s" % (self.name, self.value)960 def get_activity(self):961 return self.result_indicator_baseline.result_indicator.result.activity962class ResultIndicatorPeriodTargetComment(models.Model):963 result_indicator_period_target = models.ForeignKey(964 ResultIndicatorPeriodTarget, on_delete=models.CASCADE)965 narratives = GenericRelation(966 Narrative,967 content_type_field='related_content_type',968 object_id_field='related_object_id')969 def get_activity(self):970 return self.result_indicator_period.result_indicator.result.activity971class ResultIndicatorPeriodActualComment(models.Model):972 result_indicator_period_actual = models.ForeignKey(973 ResultIndicatorPeriodActual, on_delete=models.CASCADE)974 narratives = GenericRelation(975 Narrative,976 content_type_field='related_content_type',977 object_id_field='related_object_id')978 def get_activity(self):979 return self.result_indicator_period.result_indicator.result.activity980class Description(models.Model):981 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)982 narratives = GenericRelation(983 Narrative,984 content_type_field='related_content_type',985 object_id_field='related_object_id')986 # TODO: set a default or require987 type = models.ForeignKey(988 DescriptionType,989 related_name="description_type",990 null=True,991 blank=True,992 default=None, on_delete=models.CASCADE)993 def __unicode__(self,):994 return "Description with type %s" % self.type995 def get_activity(self):996 return self.activity997class Budget(models.Model):998 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)999 type = models.ForeignKey(1000 BudgetType, null=True, blank=True,1001 default=None, on_delete=models.CASCADE)1002 status = models.ForeignKey(1003 BudgetStatus, default=1, on_delete=models.CASCADE)1004 period_start = models.DateField(blank=True, default=None)1005 period_end = models.DateField(blank=True, default=None)1006 value = models.DecimalField(1007 max_digits=15, decimal_places=2, null=True, blank=True)1008 value_string = models.CharField(max_length=50)1009 value_date = models.DateField(null=True, blank=True, default=None)1010 currency = models.ForeignKey(1011 Currency, null=True, blank=True,1012 default=None, on_delete=models.CASCADE)1013 usd_exchange_rate = models.DecimalField(max_digits=15, decimal_places=5,1014 null=True)1015 imf_url = models.TextField(null=True)1016 xdr_value = models.DecimalField(1017 max_digits=20, decimal_places=7, default=Decimal(0))1018 usd_value = models.DecimalField(1019 max_digits=20, decimal_places=2, default=Decimal(0))1020 eur_value = models.DecimalField(1021 max_digits=20, decimal_places=7, default=Decimal(0))1022 gbp_value = models.DecimalField(1023 max_digits=20, decimal_places=7, default=Decimal(0))1024 jpy_value = models.DecimalField(1025 max_digits=20, decimal_places=7, default=Decimal(0))1026 cad_value = models.DecimalField(1027 max_digits=20, decimal_places=7, default=Decimal(0))1028 def __unicode__(self,):1029 return "value: %s - period_start: %s - period_end: %s" % (1030 str(self.value), self.period_start, self.period_end)1031 def get_activity(self):1032 return self.activity1033# same as TransactionSector, to set percentages per budget item per sector1034# this makes calculations easier (no subqueries required).1035class BudgetSector(models.Model):1036 budget = models.ForeignKey(1037 Budget,1038 on_delete=models.CASCADE)1039 sector = models.ForeignKey(1040 Sector,1041 on_delete=models.CASCADE)1042 percentage = models.CharField(max_length=100, null=True, blank=True)1043 def __unicode__(self, ):1044 return "%s - %s" % (self.budget.id, self.sector.code)1045 def get_activity(self):1046 return self.budget.activity1047class PlannedDisbursement(models.Model):1048 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)1049 type = models.ForeignKey(1050 BudgetType, null=True, blank=True,1051 default=None, on_delete=models.CASCADE)1052 period_start = models.DateField(blank=True, default=None)1053 period_end = models.DateField(null=True, blank=True, default=None)1054 value = models.DecimalField(1055 max_digits=15, decimal_places=2, null=True, blank=True)1056 value_string = models.CharField(max_length=50)1057 value_date = models.DateField(null=True, blank=True, default=None)1058 currency = models.ForeignKey(1059 Currency, null=True, blank=True,1060 default=None, on_delete=models.CASCADE)1061 usd_exchange_rate = models.DecimalField(max_digits=15, decimal_places=5,1062 null=True)1063 imf_url = models.TextField(null=True)1064 xdr_value = models.DecimalField(1065 max_digits=20, decimal_places=7, default=Decimal(0))1066 usd_value = models.DecimalField(1067 max_digits=20, decimal_places=2, default=Decimal(0))1068 eur_value = models.DecimalField(1069 max_digits=20, decimal_places=7, default=Decimal(0))1070 gbp_value = models.DecimalField(1071 max_digits=20, decimal_places=7, default=Decimal(0))1072 jpy_value = models.DecimalField(1073 max_digits=20, decimal_places=7, default=Decimal(0))1074 cad_value = models.DecimalField(1075 max_digits=20, decimal_places=7, default=Decimal(0))1076 def __unicode__(self,):1077 return "value: %s - period_start: %s - period_end: %s" % (1078 str(self.value), self.period_start, self.period_end)1079 def get_activity(self):1080 return self.activity1081class PlannedDisbursementProvider(models.Model):1082 ref = models.CharField(blank=True, default="", max_length=250)1083 normalized_ref = models.CharField(max_length=120, default="")1084 organisation = models.ForeignKey(1085 Organisation,1086 related_name="planned_disbursement_providing_organisation",1087 on_delete=models.SET_NULL,1088 null=True,1089 blank=True,1090 default=None)1091 type = models.ForeignKey(1092 OrganisationType,1093 null=True,1094 default=None,1095 blank=True,1096 on_delete=models.CASCADE1097 )1098 provider_activity = models.ForeignKey(1099 Activity,1100 related_name="planned_disbursement_provider_activity",1101 on_delete=models.SET_NULL,1102 null=True,1103 blank=True,1104 default=None)1105 provider_activity_ref = models.CharField(1106 db_index=True,1107 max_length=200,1108 null=True,1109 blank=True,1110 default="",1111 verbose_name='provider-activity-id')1112 planned_disbursement = models.OneToOneField(1113 PlannedDisbursement,1114 related_name="provider_organisation", on_delete=models.CASCADE)1115 narratives = GenericRelation(1116 Narrative,1117 content_type_field='related_content_type',1118 object_id_field='related_object_id')1119 # first narrative1120 primary_name = models.CharField(1121 max_length=250,1122 null=False,1123 blank=True,1124 default="",1125 db_index=True)1126 def __unicode__(self, ):1127 return "%s - %s" % (self.ref,1128 self.provider_activity_ref,)1129 def get_activity(self):1130 return self.planned_disbursement.activity1131class PlannedDisbursementReceiver(models.Model):1132 ref = models.CharField(blank=True, default="", max_length=250)1133 normalized_ref = models.CharField(max_length=120, default="")1134 organisation = models.ForeignKey(1135 Organisation,1136 related_name="planned_disbursement_receiving_organisation",1137 on_delete=models.SET_NULL,1138 null=True,1139 blank=True,1140 default=None)1141 type = models.ForeignKey(1142 OrganisationType,1143 null=True,1144 default=None,1145 blank=True,1146 on_delete=models.CASCADE1147 )1148 receiver_activity = models.ForeignKey(1149 Activity,1150 related_name="planned_disbursement_receiver_activity",1151 on_delete=models.SET_NULL,1152 null=True,1153 blank=True,1154 default=None)1155 receiver_activity_ref = models.CharField(1156 db_index=True,1157 max_length=200,1158 null=True,1159 blank=True,1160 default="",1161 verbose_name='receiver-activity-id')1162 planned_disbursement = models.OneToOneField(1163 PlannedDisbursement,1164 related_name="receiver_organisation", on_delete=models.CASCADE)1165 narratives = GenericRelation(1166 Narrative,1167 content_type_field='related_content_type',1168 object_id_field='related_object_id')1169 # first narrative1170 primary_name = models.CharField(1171 max_length=250,1172 null=False,1173 blank=True,1174 default="",1175 db_index=True)1176 def __unicode__(self, ):1177 return "%s - %s" % (self.ref,1178 self.receiver_activity_ref,)1179 def get_activity(self):1180 return self.planned_disbursement.activity1181class Conditions(models.Model):1182 activity = models.OneToOneField(1183 Activity, related_name="conditions", on_delete=models.CASCADE)1184 attached = models.BooleanField()1185 def get_activity(self):1186 return self.activity1187class Condition(models.Model):1188 conditions = models.ForeignKey(Conditions, on_delete=models.CASCADE)1189 type = models.ForeignKey(1190 ConditionType, null=True, blank=True,1191 default=None, on_delete=models.CASCADE)1192 narratives = GenericRelation(1193 Narrative,1194 content_type_field='related_content_type',1195 object_id_field='related_object_id')1196 def get_activity(self):1197 return self.conditions.activity1198class Location(models.Model):1199 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)1200 result_indicator_baseline = models.ForeignKey(1201 ResultIndicatorBaseline,1202 null=True,1203 blank=True,1204 on_delete=models.CASCADE,1205 )1206 ref = models.CharField(max_length=200, default=None, null=True, blank=True)1207 location_reach = models.ForeignKey(1208 GeographicLocationReach,1209 null=True,1210 blank=True,1211 default=None,1212 related_name="location_reach", on_delete=models.CASCADE)1213 # TODO: make location_id a one-to-one field?1214 location_id_vocabulary = models.ForeignKey(1215 GeographicVocabulary,1216 null=True,1217 blank=True,1218 default=None,1219 related_name="location_id_vocabulary",1220 on_delete=models.CASCADE)1221 location_id_code = models.CharField(blank=True, max_length=255, null=True,1222 default=None)1223 location_class = models.ForeignKey(1224 GeographicLocationClass,1225 null=True,1226 blank=True,1227 default=None, on_delete=models.CASCADE)1228 feature_designation = models.ForeignKey(1229 LocationType,1230 null=True,1231 blank=True,1232 default=None,1233 related_name="feature_designation", on_delete=models.CASCADE)1234 point_srs_name = models.CharField(1235 null=True,1236 blank=True,1237 max_length=255,1238 default=None1239 )1240 point_pos = PointField(1241 null=True,1242 blank=False,1243 default=None,1244 spatial_index=True,1245 srid=4326,1246 geography=True)1247 exactness = models.ForeignKey(1248 GeographicExactness, null=True, blank=True,1249 default=None, on_delete=models.CASCADE)1250 objects = LocationManager()1251 def __unicode__(self,):1252 return "Location: %s" % self.point_pos1253 def get_activity(self):1254 return self.activity1255# TODO: move to codelist1256class LocationAdministrative(models.Model):1257 location = models.ForeignKey(Location, on_delete=models.CASCADE)1258 code = models.CharField(max_length=255)1259 vocabulary = models.ForeignKey(1260 GeographicVocabulary,1261 related_name="administrative_vocabulary", on_delete=models.CASCADE)1262 level = models.IntegerField(null=True, blank=True, default=None)1263 def get_activity(self):1264 return self.location.activity1265class LocationName(models.Model):1266 location = models.OneToOneField(1267 Location, related_name="name", on_delete=models.CASCADE)1268 narratives = GenericRelation(1269 Narrative,1270 content_type_field='related_content_type',1271 object_id_field='related_object_id')1272 def get_activity(self):1273 return self.location.activity1274class LocationDescription(models.Model):1275 location = models.OneToOneField(1276 Location, related_name="description", on_delete=models.CASCADE)1277 narratives = GenericRelation(1278 Narrative,1279 content_type_field='related_content_type',1280 object_id_field='related_object_id')1281 def get_activity(self):1282 return self.location.activity1283class LocationActivityDescription(models.Model):1284 location = models.OneToOneField(1285 Location, related_name="activity_description",1286 on_delete=models.CASCADE)1287 narratives = GenericRelation(1288 Narrative,1289 content_type_field='related_content_type',1290 object_id_field='related_object_id')1291 def get_activity(self):1292 return self.location.activity1293class Fss(models.Model):1294 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)1295 extraction_date = models.DateField()1296 priority = models.BooleanField(default=False)1297 phaseout_year = models.IntegerField(null=True, blank=True)1298 def __unicode__(self,):1299 return "%s" % self.extraction_date1300 def get_activity(self):1301 return self.activity1302class FssForecast(models.Model):1303 fss = models.ForeignKey(Fss, on_delete=models.CASCADE)1304 year = models.IntegerField()1305 currency = models.ForeignKey(Currency, on_delete=models.CASCADE)1306 value_date = models.DateField()1307 value = models.DecimalField(max_digits=15, decimal_places=2)1308 def __unicode__(self,):1309 return "%s" % self.year1310 def get_activity(self):1311 return self.fss.activity1312class CrsAdd(models.Model):1313 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)1314 channel_code = models.ForeignKey(CRSChannelCode, null=True,1315 on_delete=models.CASCADE)1316 def __unicode__(self,):1317 return "%s" % self.id1318 def get_activity(self):1319 return self.activity1320class CrsAddOtherFlags(models.Model):1321 crs_add = models.ForeignKey(1322 CrsAdd, related_name="other_flags", on_delete=models.CASCADE)1323 other_flags = models.ForeignKey(OtherFlags, on_delete=models.CASCADE)1324 significance = models.BooleanField()1325 def __unicode__(self,):1326 return "%s" % self.id1327 def get_activity(self):1328 return self.crs_add.activity1329class CrsAddLoanTerms(models.Model):1330 crs_add = models.OneToOneField(1331 CrsAdd, related_name="loan_terms", on_delete=models.CASCADE)1332 rate_1 = models.DecimalField(1333 null=True,1334 blank=True,1335 default=None,1336 max_digits=5,1337 decimal_places=2)1338 rate_2 = models.DecimalField(1339 null=True,1340 blank=True,1341 default=None,1342 max_digits=5,1343 decimal_places=2)1344 repayment_type = models.ForeignKey(1345 LoanRepaymentType,1346 null=True,1347 blank=True,1348 default=None, on_delete=models.CASCADE)1349 repayment_plan = models.ForeignKey(1350 LoanRepaymentPeriod,1351 null=True,1352 blank=True,1353 default=None, on_delete=models.CASCADE)1354 commitment_date = models.DateField(null=True, blank=True, default=None)1355 repayment_first_date = models.DateField(1356 null=True, blank=True, default=None)1357 repayment_final_date = models.DateField(1358 null=True, blank=True, default=None)1359 def __unicode__(self,):1360 return "%s" % self.crs_add_id1361 def get_activity(self):1362 return self.crs_add.activity1363class CrsAddLoanStatus(models.Model):1364 crs_add = models.OneToOneField(1365 CrsAdd, related_name="loan_status", on_delete=models.CASCADE)1366 year = models.IntegerField(null=True, blank=True, default=None)1367 value_date = models.DateField(null=True, blank=True, default=None)1368 currency = models.ForeignKey(1369 Currency, null=True, blank=True,1370 default=None, on_delete=models.CASCADE)1371 interest_received = models.DecimalField(1372 null=True,1373 blank=True,1374 default=None,1375 max_digits=15,1376 decimal_places=2)1377 principal_outstanding = models.DecimalField(1378 null=True,1379 blank=True,1380 default=None,1381 max_digits=15,1382 decimal_places=2)1383 principal_arrears = models.DecimalField(1384 null=True,1385 blank=True,1386 default=None,1387 max_digits=15,1388 decimal_places=2)1389 interest_arrears = models.DecimalField(1390 null=True,1391 blank=True,1392 default=None,1393 max_digits=15,1394 decimal_places=2)1395 def __unicode__(self):1396 return "%s" % self.year1397 def get_activity(self):1398 return self.crs_add.activity1399class ActivityDate(models.Model):1400 """1401 Reference:1402 http://reference.iatistandard.org/201/activity-standard/iati-activities/iati-activity/activity-date/1403 """1404 # TODO: activity-date should have narratives1405 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)1406 iso_date = models.DateField()1407 type = models.ForeignKey(ActivityDateType, on_delete=models.CASCADE)1408 narratives = GenericRelation(1409 Narrative,1410 content_type_field='related_content_type',1411 object_id_field='related_object_id'1412 )1413 def __unicode__(self):1414 return "type: %s - iso_date: %s" % (1415 self.type, self.iso_date.strftime('%Y-%m-%d')1416 )1417 def get_activity(self):1418 return self.activity1419class LegacyData(models.Model):1420 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)1421 name = models.CharField(max_length=150, null=True, blank=True)1422 value = models.CharField(max_length=200, null=True, blank=True)1423 iati_equivalent = models.CharField(max_length=150, null=True, blank=True)1424 def __unicode__(self):1425 return "%s" % self.name1426 def get_activity(self):1427 return self.activity1428class ActivityTag(models.Model):1429 """A model to store Tags on Activity (introduced in 2.03)1430 Actual tag values are stored in Narrative model:1431 Narrative.objects.filter(1432 related_content_type__model='activitytag',1433 activity=activity_model_instance,1434 ).values_list('content')1435 In the future (if needed), implement a separate field for storing tag value1436 or s separate method (get_tag_value) to get it from Narratives or smth.1437 """1438 activity = models.ForeignKey(Activity, on_delete=models.CASCADE)1439 code = models.CharField(max_length=255)1440 vocabulary = models.ForeignKey(...
SFC_backprop_main.py
Source:SFC_backprop_main.py
...156 matplotlib.rcParams['pgf.texsystem'] = 'pdflatex'157 plt.savefig('./rasterplot_annotated.svg')158if do_train:159 try:160 print(np.sum(bp_sfc.get_activity('h1', 2)))161 print(np.sum(bp_sfc.get_activity('o', 3)))162 for i in [1, 4, 6, 8, 10, 0]:163 print('phase:', i, end=' ')164 assert 0 == (np.sum(bp_sfc.get_activity('h1', i)))165 assert 0 == (np.sum(bp_sfc.get_activity('h1_copy', i)))166 assert 0 == (np.sum(bp_sfc.get_activity('h1_copy2', i)))167 assert 0 == (np.sum(bp_sfc.get_activity('o', i)))168 assert 0 == (np.sum(bp_sfc.get_activity('o_copy', i)))169 assert 0 == (np.sum(bp_sfc.get_activity('o_copy2', i)))170 assert 0 == (np.sum(bp_sfc.get_activity('o', i)))171 print('OK, silent')172 for i in [0, 1, 2, 3, 4, 7, 8, 11]:173 assert 0 == (np.sum(bp_sfc.get_activity('h1T', i)))174 for i in range(bp_sfc.num_gate):175 print('phase:', i, end=' ')176 print(np.sum(bp_sfc.get_activity('x', i)))177 except KeyError:178 pass179 # bp_sfc.get_activity('x', 1)[:100]==bp_sfc.get_activity('x', 11)180 try:181 assert (w_final['w1'] == w_final['w1_copy1']).all()182 assert (w_final['w1'] == w_final['w1_copy2']).all()183 except KeyError:184 pass185 try:186 assert (w_final['w1_copy1'] == w_final['w1_copy2']).all()187 assert (w_final['w2'] == w_final['w2_copy1']).all()188 assert (w_final['w2'] == w_final['w2_copy2']).all()189 except KeyError:190 pass191 assert (w_final['w2'].T == w_final['w2Tp']).all(), np.sum(np.abs(w_final['w2'].T - w_final['w2Tp']))192 print((w_final['w2'].T == -w_final['w2Tm']).all(), np.sum(np.abs(w_final['w2'].T + w_final['w2Tm'])))193 print((w_final['w2Tp'] == -w_final['w2Tm']).all(), np.sum(np.abs(w_final['w2Tm'] + w_final['w2Tp'])))...
layers.py
Source:layers.py
...9 self.spikes = np.zeros(self.N)10 11 def update_activity(self, pos):12 13 self.firing_rates, self.spikes = self.neuron_model.get_activity(pos, get_spikes=True)14class CA1_layer:15 def __init__(self, N_ca3, conf):16 self.place_model = Place_Cells(conf)17 self.N = self.place_model.N18 self.N_in = N_ca319 self.SRM0_model = SRM0(N_ca3, self.N, conf) 20 self.alpha = conf['alpha']21 # activity state22 self.spikes = np.zeros(self.N)23 self.firing_rates = np.zeros(self.N)24 # weights25 self.w_min = conf['w_min']26 self.w_max = conf['w_max']27 self.weight_decay = conf['weight_decay']28 self.base_weight = conf['base_weight']29 def update_activity(self, pos, spikes, time):30 if self.alpha == 0: 31 self.firing_rates = self.place_model.get_activity(pos)32 33 elif self.alpha == 1:34 self.firing_rates = self.SRM0_model.get_activity(spikes,time)35 else:36 37 lambda_pos = self.place_model.get_activity(pos)38 lambda_u = self.SRM0_model.get_activity(spikes, time)39 self.firing_rates = self.alpha*lambda_u + (1-self.alpha)*lambda_pos40 self.spikes = np.random.rand(self.N) <= self.firing_rates41 def update_weights(self, update):42 if self.weight_decay != 0:43 44 decay = self.SRM0_model.W - self.base_weight45 decay = np.where(decay>0, decay, 0)46 self.SRM0_model.W -= self.weight_decay*decay47 self.SRM0_model.W += update48 self.SRM0_model.W = np.clip(self.SRM0_model.W, self.w_min, self.w_max)49class Action_layer:50 def __init__(self, N_in, conf):51 self.N = conf['N']52 self.N_in = N_in53 self.neuron_model = SRM0(N_in, self.N, conf) 54 55 self.firing_rates = np.zeros(self.N)56 self.spikes = np.zeros(self.N)57 # to produce action58 self.thetas = 2*np.pi*np.arange(1,self.N+1)*(1./self.N)59 self.actions = conf['a0']*np.array([np.cos(self.thetas), np.sin(self.thetas)])60 self.fixed_step = conf['fixed_step'] if conf['use_fixed_step'] else None61 # To handle weights updates62 self.weight_decay = conf['weight_decay']63 self.base_weight = conf['base_weight']64 self.w_min = conf['w_min']65 self.w_max = conf['w_max'] 66 67 def update_activity(self, spikes_ca1, time):68 69 self.firing_rates, self.spikes = self.neuron_model.get_activity(spikes_ca1, time, get_spikes=True)70 71 def update_weights(self, update):72 if self.weight_decay != 0:73 74 decay = self.neuron_model.W - self.base_weight75 decay = np.where(decay>0, decay, 0)76 self.neuron_model.W -= self.weight_decay*decay77 self.neuron_model.W += update78 self.neuron_model.W = np.clip(self.neuron_model.W, self.w_min, self.w_max) 79 def get_action(self,):80 81 a = np.einsum('ij, j -> i', self.actions, self.firing_rates)82 83 if self.fixed_step is not None:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!