mirror of
https://github.com/jung-geun/PSO.git
synced 2025-12-20 04:50:45 +09:00
23-07-06
code space용 설정 파일 추가 mutation 설정 - 특정 확률로 파티클의 위치를 랜덤하게 방향 조정
This commit is contained in:
16
.devcontainer/Dockerfile
Normal file
16
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
FROM mcr.microsoft.com/devcontainers/miniconda:0-3
|
||||||
|
|
||||||
|
# Copy environment.yml (if found) to a temp location so we update the environment. Also
|
||||||
|
# copy "noop.txt" so the COPY instruction does not fail if no environment.yml exists.
|
||||||
|
COPY environment.yml* .devcontainer/noop.txt /tmp/conda-tmp/
|
||||||
|
RUN if [ -f "/tmp/conda-tmp/environment.yml" ]; then umask 0002 && /opt/conda/bin/conda env update -n base -f /tmp/conda-tmp/environment.yml; fi \
|
||||||
|
&& rm -rf /tmp/conda-tmp
|
||||||
|
|
||||||
|
# [Optional] Uncomment to install a different version of Python than the default
|
||||||
|
# RUN conda install -y python=3.6 \
|
||||||
|
# && pip install --no-cache-dir pipx \
|
||||||
|
# && pipx reinstall-all
|
||||||
|
|
||||||
|
# [Optional] Uncomment this section to install additional OS packages.
|
||||||
|
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||||
|
# && apt-get -y install --no-install-recommends <your-package-list-here>
|
||||||
43
.devcontainer/devcontainer.json
Normal file
43
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||||
|
// README at: https://github.com/devcontainers/templates/tree/main/src/miniconda
|
||||||
|
{
|
||||||
|
"name": "Miniconda (Python 3)",
|
||||||
|
"build": {
|
||||||
|
"context": "..",
|
||||||
|
"dockerfile": "Dockerfile"
|
||||||
|
},
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"extensions": [
|
||||||
|
"ms-python.python",
|
||||||
|
"ms-toolsai.jupyter"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers/features/nvidia-cuda:1": {
|
||||||
|
"installCudnn": true
|
||||||
|
},
|
||||||
|
"ghcr.io/devcontainers/features/anaconda:1": {
|
||||||
|
"version": "latest"
|
||||||
|
},
|
||||||
|
"ghcr.io/devcontainers/features/python:1": {
|
||||||
|
"installTools": true,
|
||||||
|
"version": "3.9"
|
||||||
|
},
|
||||||
|
"ghcr.io/rocker-org/devcontainer-features/miniforge:1": {
|
||||||
|
"version": "latest",
|
||||||
|
"variant": "Miniforge-pypy3"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Features to add to the dev container. More info: https://containers.dev/features.
|
||||||
|
// "features": {},
|
||||||
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
|
// "forwardPorts": [],
|
||||||
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
|
// "postCreateCommand": "python --version",
|
||||||
|
// Configure tool-specific properties.
|
||||||
|
// "customizations": {},
|
||||||
|
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
||||||
|
// "remoteUser": "root"
|
||||||
|
}
|
||||||
3
.devcontainer/noop.txt
Normal file
3
.devcontainer/noop.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
This file is copied into the container along with environment.yml* from the
|
||||||
|
parent folder. This is done to prevent the Dockerfile COPY instruction from
|
||||||
|
failing if no environment.yml is found.
|
||||||
12
.github/workflows/python-package-conda.yml
vendored
12
.github/workflows/python-package-conda.yml
vendored
@@ -21,14 +21,6 @@ jobs:
|
|||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
conda env update --file environment.yaml --name base
|
conda env update --file environment.yaml --name base
|
||||||
- name: Lint with flake8
|
- name: pso mnist run
|
||||||
run: |
|
run: |
|
||||||
conda install flake8
|
python mnist.py
|
||||||
# stop the build if there are Python syntax errors or undefined names
|
|
||||||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
|
||||||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
|
|
||||||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
|
||||||
- name: Test with pytest
|
|
||||||
run: |
|
|
||||||
conda install pytest
|
|
||||||
pytest
|
|
||||||
@@ -90,7 +90,7 @@ class Optimizer:
|
|||||||
negative_count += 1
|
negative_count += 1
|
||||||
|
|
||||||
print(f"negative swarm : {negative_count} / {self.n_particles}")
|
print(f"negative swarm : {negative_count} / {self.n_particles}")
|
||||||
print(f"mutation swarm : {mutation_swarm*100/self.n_particles} / {self.n_particles}")
|
print(f"mutation swarm : {mutation_swarm * self.n_particles} / {self.n_particles}")
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
|
|
||||||
|
|||||||
@@ -150,9 +150,11 @@ class Particle:
|
|||||||
+ local_rate * r0 * (encode_p - encode_w)
|
+ local_rate * r0 * (encode_p - encode_w)
|
||||||
+ global_rate * r1 * (encode_g - encode_w)
|
+ global_rate * r1 * (encode_g - encode_w)
|
||||||
)
|
)
|
||||||
if np.random.rand() < self.mutation:
|
|
||||||
|
|
||||||
new_v += 0.5 * encode_v
|
if np.random.rand() < self.mutation:
|
||||||
|
m_v = np.random.uniform(-0.1, 0.1, len(encode_v))
|
||||||
|
new_v = m_v
|
||||||
|
|
||||||
self.velocities = self._decode(new_v, w_sh, w_len)
|
self.velocities = self._decode(new_v, w_sh, w_len)
|
||||||
|
|
||||||
del encode_w, w_sh, w_len
|
del encode_w, w_sh, w_len
|
||||||
@@ -193,8 +195,11 @@ class Particle:
|
|||||||
+ local_rate * r0 * (w_p * encode_p - encode_w)
|
+ local_rate * r0 * (w_p * encode_p - encode_w)
|
||||||
+ global_rate * r1 * (w_g * encode_g - encode_w)
|
+ global_rate * r1 * (w_g * encode_g - encode_w)
|
||||||
)
|
)
|
||||||
if self.mutation:
|
|
||||||
new_v += 0.5 * encode_v
|
if np.random.rand() < self.mutation:
|
||||||
|
m_v = np.random.uniform(-0.1, 0.1, len(encode_v))
|
||||||
|
new_v = m_v
|
||||||
|
|
||||||
self.velocities = self._decode(new_v, w_sh, w_len)
|
self.velocities = self._decode(new_v, w_sh, w_len)
|
||||||
|
|
||||||
del encode_w, w_sh, w_len
|
del encode_w, w_sh, w_len
|
||||||
|
|||||||
Reference in New Issue
Block a user