This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final_loss = \ | |
# average over all the colocation points | |
de_loss_vec.pow(2).mean() + \ | |
# simply square the boundary contribution which is a single value | |
boundary_loss ** 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
de_loss_vec = dfdt(nn, t) - R * t * (1 - t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
T_0 = 0 | |
F_0 = 1 | |
boundary = torch.Tensor([T_0]) | |
boundary.requires_grad = True | |
boundary_loss = f(nn, boundary) - F0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
def f(nn: NNApproximator, x: torch.Tensor) -> torch.Tensor: | |
"""Compute the value of the approximate solution from the NN model""" | |
return nn(x) | |
def df(nn: NNApproximator, x: torch.Tensor = None, order: int = 1) -> torch.Tensor: | |
"""Compute neural network derivative with respect to the input feature(s) using PyTorch autograd engine""" | |
df_value = f(nn, x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torch import nn | |
class NNApproximator(nn.Module): | |
def __init__( | |
self, | |
num_inputs: int = 1, | |
num_outputs: int = 1, | |
num_hidden: int = 1, | |
dim_hidden: int = 1, | |
act: nn.Module = nn.Tanh(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_iam_policy" "snapshot_passrole_policy" { | |
name = "snapshot_passrole_policy" | |
path = "/" | |
description = "Allow role to assume the snapshot role to create OpenSearch snapshots" | |
policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module "lambda" { | |
source = "terraform-aws-modules/lambda/aws" | |
function_name = "lambda-es-backup" | |
description = "OpenSearch domain snapshot backup" | |
handler = "es_snapshot_handler.lambda_handler" | |
runtime = "python3.9" | |
attach_policy = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "aws_iam_policy_document" "es_role_policy" { | |
statement { | |
actions = ["sts:AssumeRole"] | |
principals { | |
type = "Service" | |
identifiers = ["es.amazonaws.com"] | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from datetime import datetime | |
from uuid import uuid4 | |
import boto3 | |
import requests | |
from requests_aws4auth import AWS4Auth | |
# configuration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_cloudwatch_event_rule" "cron_schedule" { | |
name = "es_backup_lambda_cron_schedule" | |
description = "Daily execution" | |
schedule_expression = "rate(1 day)" | |
} |