Replies: 1 comment 1 reply
-
You can keep a certain number of digits. Also, maybe we should use |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
To generate input files , I have wrote a script in which folders of datasets prepared by dpdata.py and the sampling probability were inputs. With this script, I assign probability of training to the folders, while the probabilities of each sub-folder determined by the number of frames.
Due to the computing mechanism of floats in python, sometimes the sum of sys_probs generate by my scripts did not equal "1" and would raise error in deepmd-kit. Is there any methods to solve the problem?
My script:
import sys
import os
import json
rawfolders = sys.argv[1:]
ratio_prob = input("relative of probability of the data_sets:")
ratio_prob = ratio_prob.strip().split()
ratio_list = [float(x) for x in ratio_prob[:len(sys.argv[1:])]]
relative_prob = [x/sum(ratio_list) for x in ratio_list]
print(relative_prob)
datasets = []
prob = []
for index, ff in enumerate(rawfolders):
presys = os.listdir(ff)
nfrs = []
for i in presys:
targets = os.path.join(ff,i)
if os.path.isdir(targets) and os.path.isfile("%s/force.raw" %(targets)):
datasets.append(targets)
tmp = open("%s/force.raw" %(targets),"r").readlines()
nfr = len(tmp)
nfrs.append(nfr)
temp_prob = [ relative_prob[index]*x/sum(nfrs) for x in nfrs]
prob = prob + temp_prob
prob = [round(x/sum(prob),4) for x in prob]
print(sum(prob))
prob[prob.index(max(prob))] += 1.0 - sum(prob)
print(sum(prob))
alldata = dict(zip(datasets,prob))
print(alldata)
with open("/home/user/input/deepmd/train_input.json","r") as tp:
input = json.load(tp)
input["training"]["training_data"]["systems"] = datasets
input["training"]["training_data"]["sys_probs"] = prob
input["training"]["validation_data"]["systems"] = datasets
input["training"]["validation_data"]["sys_probs"] = prob
with open("newinput.json",'w') as new:
json.dump(input,new,indent=4)
Beta Was this translation helpful? Give feedback.
All reactions